我正在尝试通过 jupyter 笔记本在我的电脑上运行图形绘制代码。我的电脑上安装了 Networkx 、pygraphviz 和 nxpd 。但运行后发现 AttributeError绘制(G,布局='circo')我该如何解决这个问题?错误在下面的描述中:AttributeError Traceback (most recent call last)<ipython-input-2-d4524714330e> in <module>----> 1 draw(G, layout='circo')~/anaconda3/lib/python3.7/site-packages/nxpd/nx_pydot.py in draw_pydot(G, filename, format, prefix, suffix, layout, args, show) 455 456 # Draw the image.--> 457 G2 = to_pydot(G) 458 G2.write(fobj, prog=prog, format=ext) 459 if close:~/anaconda3/lib/python3.7/site-packages/nxpd/nx_pydot.py in to_pydot(G, raise_exceptions) 247 graph_type = 'graph' 248 --> 249 strict = G.number_of_selfloops() == 0 and not G.is_multigraph() 250 251 # Create the Pydot graph.AttributeError: 'DiGraph' object has no attribute 'number_of_selfloops'代码如下:import networkx as nximport pygraphviz as pgvfrom nxpd import draw, nxpdParamsnxpdParams['show'] = 'ipynb'G = nx.DiGraph()G.add_edge("a", "b")G.add_edge("b", "c")G.add_edge("c", "d")G.add_edge("d", "e")G.add_edge("e", "c")G.add_edge("a", "d")draw(G, layout='circo')
1 回答
DIEA
TA贡献1820条经验 获得超2个赞
该软件包nxpd
似乎是几年前最后一次更新的。您可以自己修改该行(参见https://github.com/chebee7i/nxpd/blob/master/nxpd/nx_pydot.py#L249)并G.number_of_selfloops
与nx.number_of_selfloops(G)
. 然而,我想他们有更多的问题nxpd
,我建议简单地使用networkx
自己的接口graphviz
,参见例如graphviz_layout
:
pos = nx.nx_agraph.graphviz_layout(G, prog="circo") nx.draw(G, pos)
添加回答
举报
0/150
提交
取消