“DiGraph”对象没有属性“number_of_selfloops”

我正在尝试通过 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')


BIG阳
浏览 138回答 1
1回答

DIEA

该软件包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)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python