我正在尝试通过 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 nx
import pygraphviz as pgv
from nxpd import draw, nxpdParams
nxpdParams['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')
DIEA
相关分类