How to draw parallel edges in Networkx / Graphviz

北城余情 提交于 2020-01-22 15:12:21

问题


I am trying to add parallel edges between two nodes using NetworkX but it fails with the below error. What am I doing wrong?

import networkx as nx
import graphviz

g1 = nx.MultiGraph()

node1 = 'a'
node2 = 'b'

g1.add_edge(node1,node2,key='one')
g1.add_edge(node1,node2,key='two')

A = nx.to_agraph(g1)
A.add_subgraph()

A.draw('test2.png', prog='dot')

Error:

Traceback (most recent call last):
  File "test2.py", line 12, in <module>
    A = nx.to_agraph(g1)
  File "C:\python27\lib\site-packages\networkx-1.11rc1-py2.7.egg\networkx\drawing\nx_agraph.py", line 152, in to_agraph
    A.add_edge(u,v,key=str(key),**str_edgedata)
  File "C:\python27\lib\site-packages\pygraphviz\agraph.py", line 481, in add_edge
    eh = gv.agedge(self.handle, uh, vh, key, _Action.find)
KeyError: 'agedge: no key'

回答1:


Your code is working fine, and I attached the output image.



来源:https://stackoverflow.com/questions/35007046/how-to-draw-parallel-edges-in-networkx-graphviz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!