使用pydot绘制图形时断言错误
Assertion error while drawing graph with pydot
我刚开始使用 pydot 创建图表。我刚刚创建了一个节点,但在尝试使用 jupyter notebook 显示图形时遇到了问题。
这是我的代码:
import pydot
import os
from IPython.display import Image, display
G= pydot.Dot(graph_type='digraph')
node = pydot.Node("S'->.S\nS->.(L)/.a")
G.add_node(node)
im = Image(G.create_png())
display(im)
下面是我的错误
"dot" with args ['-Tpng', 'C:\Users\MAYANK~1\AppData\Local\Temp\tmptw6hrboj'] returned code: 1
stdout, stderr:
b''
b"'C:\Users\Mayank' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-10-fb336e9303b4> in <module>
5 node = pydot.Node("S'->.S\nS->.(L)/.a")
6 G.add_node(node)
----> 7 im = Image(G.create_png())
8 display(im)
~\anaconda3\lib\site-packages\pydot.py in new_method(f, prog, encoding)
1721 """Refer to docstring of method `create`."""
1722 return self.create(
-> 1723 format=f, prog=prog, encoding=encoding)
1724 name = 'create_{fmt}'.format(fmt=frmt)
1725 self.__setattr__(name, new_method)
~\anaconda3\lib\site-packages\pydot.py in create(self, prog, format, encoding)
1943 print(message)
1944
-> 1945 assert process.returncode == 0, process.returncode
1946
1947 return stdout_data
AssertionError: 1
请帮我清除这个错误!!
因为名声我不能评论,但我可以说当
pos = graphviz_layout(temp_nx, prog="dot")
给我一个断言错误,
pos = nx.nx_agraph.pygraphviz_layout(temp_nx, prog='dot')
工作
我可以使用 nx.DiGraph 而不是 nx.Graph
来解决这个问题
import networkx as nx
from networkx.drawing.nx_pydot import graphviz_layout
G = nx.DiGraph()
# add stuff to graph
fig = plt.figure()
pos = graphviz_layout(self.tree, prog='dot')
nx.draw_networkx_nodes(self.tree, pos)
nx.draw_networkx_edges(self.tree, pos)
plt.show()
我刚开始使用 pydot 创建图表。我刚刚创建了一个节点,但在尝试使用 jupyter notebook 显示图形时遇到了问题。 这是我的代码:
import pydot
import os
from IPython.display import Image, display
G= pydot.Dot(graph_type='digraph')
node = pydot.Node("S'->.S\nS->.(L)/.a")
G.add_node(node)
im = Image(G.create_png())
display(im)
下面是我的错误
"dot" with args ['-Tpng', 'C:\Users\MAYANK~1\AppData\Local\Temp\tmptw6hrboj'] returned code: 1
stdout, stderr:
b''
b"'C:\Users\Mayank' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-10-fb336e9303b4> in <module>
5 node = pydot.Node("S'->.S\nS->.(L)/.a")
6 G.add_node(node)
----> 7 im = Image(G.create_png())
8 display(im)
~\anaconda3\lib\site-packages\pydot.py in new_method(f, prog, encoding)
1721 """Refer to docstring of method `create`."""
1722 return self.create(
-> 1723 format=f, prog=prog, encoding=encoding)
1724 name = 'create_{fmt}'.format(fmt=frmt)
1725 self.__setattr__(name, new_method)
~\anaconda3\lib\site-packages\pydot.py in create(self, prog, format, encoding)
1943 print(message)
1944
-> 1945 assert process.returncode == 0, process.returncode
1946
1947 return stdout_data
AssertionError: 1
请帮我清除这个错误!!
因为名声我不能评论,但我可以说当
pos = graphviz_layout(temp_nx, prog="dot")
给我一个断言错误,
pos = nx.nx_agraph.pygraphviz_layout(temp_nx, prog='dot')
工作
我可以使用 nx.DiGraph 而不是 nx.Graph
来解决这个问题import networkx as nx
from networkx.drawing.nx_pydot import graphviz_layout
G = nx.DiGraph()
# add stuff to graph
fig = plt.figure()
pos = graphviz_layout(self.tree, prog='dot')
nx.draw_networkx_nodes(self.tree, pos)
nx.draw_networkx_edges(self.tree, pos)
plt.show()