我正在尝试在 python 的 networkx 中的 graphviz 布局中绘制一个 100 节点多图 G,所以到目前为止我进行了两次试验:
试用 1 nx.draw_graphviz函数如下nx.draw_graphviz(G)
,但对于图中的所有节点,我得到以下错误重复:
错误:节点 1,位置 [0.127506302389087, 0.3262608552621944],预计两个双打
然后试图找出一个解决方案,我使用试用 2 A=nx.to_agraph(G)
来获取 pygraphviz 图表,但是当我尝试绘制时,nx.draw_graphviz(A)
我得到以下错误:
AttributeError:“AGraph”对象没有属性“number_of_selfloops”
nx.graphviz_layout但它返回一个由节点键入的位置字典,我不知道如何使用它来绘制 graphviz 布局。
注意我导入了 graphviz、pygraphviz 和 pydot 模块,但我不知道哪些是真正需要的,但它仍然不起作用。
在graphviz布局中绘制networkx图是否缺少一些东西?
完整的错误跟踪
试验 1
Traceback (most recent call last):
File "main.py", line 102, in <module>
d.display_graph(sub_normal,NEUTRAL_RANGE)
File "/home/abdallah/stage/Reputation_system/display.py", line 33, in display_graph
nx.draw_graphviz(G)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pylab.py", line 982, in draw_graphviz
pos = nx.drawing.graphviz_layout(G, prog)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pydot.py", line 257, in graphviz_layout
return pydot_layout(G=G,prog=prog,root=root,**kwds)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pydot.py", line 277, in pydot_layout
D=P.create_dot(prog=prog)
File "/usr/lib/python2.7/dist-packages/pydot.py", line 1802, in <lambda>
lambda f=frmt, prog=self.prog : self.create(format=f, prog=prog))
File "/usr/lib/python2.7/dist-packages/pydot.py", line 2023, in create
status, stderr_output) )
pydot.InvocationException: Program terminated with status: 1. stderr follows: Error: node 0, position [0.7145101895899024, 0.9016482786797262], expected two doubles
试验 2
Traceback (most recent call last):
File "main.py", line 102, in <module>
d.display_graph(sub_normal,NEUTRAL_RANGE)
File "/home/abdallah/stage/Reputation_system/display.py", line 33, in display_graph
nx.draw_graphviz(A)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pylab.py", line 982, in draw_graphviz
pos = nx.drawing.graphviz_layout(G, prog)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pydot.py", line 257, in graphviz_layout
return pydot_layout(G=G,prog=prog,root=root,**kwds)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pydot.py", line 273, in pydot_layout
P=to_pydot(G)
File "/usr/local/lib/python2.7/dist-packages/networkx-1.10-py2.7.egg/networkx/drawing/nx_pydot.py", line 192, in to_pydot
strict=N.number_of_selfloops()==0 and not N.is_multigraph()
AttributeError: 'AGraph' object has no attribute 'number_of_selfloops'