AttributeError: 'DiGraph' object has no attribute 'number_of_selfloops'
AttributeError: 'DiGraph' object has no attribute 'number_of_selfloops'
我正在尝试 运行 通过 jupyter notebook 在我的电脑中绘制图形代码。 Networkx、pygraphviz 和 nxpd 安装在我的 pc.But 我在 运行ning
之后发现了 AttributeError
draw(G, layout='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')
软件包 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)
我正在尝试 运行 通过 jupyter notebook 在我的电脑中绘制图形代码。 Networkx、pygraphviz 和 nxpd 安装在我的 pc.But 我在 运行ning
之后发现了 AttributeErrordraw(G, layout='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')
软件包 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)