“Arrows Directions, 两个单独的箭头,双向但不是双向箭头,通过一个箭头表示”

huangapple go评论92阅读模式
英文:

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:

  1. import networkx as nx
  2. from pyvis.network import Network
  3. import webbrowser
  4. # Initialize a MultiDiGraph
  5. G = nx.MultiDiGraph()
  6. # Add the edges and nodes
  7. G.add_edges_from([('A', 'B'), ('B', 'A'), ('A', 'C')])
  8. # Create a pyvis network
  9. nt = Network(height="800px", width="1600px", notebook=True)
  10. # Add the nodes to the network
  11. nt.add_nodes(G.nodes())
  12. # Add the edges to the network with arrows in both directions
  13. for source, target in G.edges():
  14. nt.add_edge(source, target, arrows='to')
  15. # Show the network
  16. nt.show("graph.html")
  17. # Open the HTML file in the browser
  18. 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)

英文:

If you set directed=True while initiating your network you should get the result you want nt = Network(height="800px", width="1600px", notebook=True,directed=True)

“Arrows Directions, 两个单独的箭头,双向但不是双向箭头,通过一个箭头表示”

huangapple
  • 本文由 发表于 2023年5月22日 04:54:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301887.html
  • networkx
  • python
  • python-3.x
  • pyvis
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定