英文:
Arrows Directions, 2 separate arrows both ways but not bidirectional depicted via 1 arrow
问题
我正在尝试生成一个图,其中有一条从'A'到'B'的箭头,一条从'B'到'A'的箭头,以及一条从'A'到'C'的箭头。我尝试使用bidirectional=True选项,但这并非对所有节点都适用,所以我不能这样做。一直在尝试不同的方法,但似乎找不到我想要的。
英文:
I have the following code that I've been working on:
import networkx as nx
from pyvis.network import Network
import webbrowser
# Initialize a MultiDiGraph
G = nx.MultiDiGraph()
# Add the edges and nodes
G.add_edges_from([('A', 'B'), ('B', 'A'), ('A', 'C')])
# Create a pyvis network
nt = Network(height="800px", width="1600px", notebook=True)
# Add the nodes to the network
nt.add_nodes(G.nodes())
# Add the edges to the network with arrows in both directions
for source, target in G.edges():
nt.add_edge(source, target, arrows='to')
# Show the network
nt.show("graph.html")
# Open the HTML file in the browser
webbrowser.open("graph.html")
I am trying to generate a graph that has a edge that has an arrow going from 'A' to 'B', an arrow going from 'B' to 'A', and an arrow going from 'A' to 'C'.
I have tried using the bidirectional=True option, but this is not always the case for all the nodes, so I cannot have that. Been playing around with it to see what I can do, but I cannot seem to find what I am looking for.
答案1
得分: 0
如果在初始化网络时设置了 directed=True
,您应该会得到您想要的结果 nt = Network(height="800px", width="1600px", notebook=True, directed=True)
。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论