0
如何繪製稱爲流圖的新類。我得到了很多的錯誤:創建圖表類
Traceback (most recent call last):
File "Graphs.py", line 26, in <module>
nx.draw(F1)
File "/home/thinkpad/anaconda3/lib/python3.4/site-packages/networkx/drawing/nx_pylab.py", line 131, in draw
draw_networkx(G, pos=pos, ax=ax, **kwds)
File "/home/thinkpad/anaconda3/lib/python3.4/site-packages/networkx/drawing/nx_pylab.py", line 262, in draw_networkx
pos = nx.drawing.spring_layout(G) # default to spring layout
File "/home/thinkpad/anaconda3/lib/python3.4/site-packages/networkx/drawing/layout.py", line 232, in fruchterman_reingold_layout
if len(G)==0:
TypeError: object of type 'FlowGraph' has no len()
代碼:
import networkx as nx
import matplotlib.pyplot as plt
class FlowGraph:
G=nx.DiGraph()
I=[]
O=[]
F1=FlowGraph()
# Add nodes
F1.G.add_node(1)
F1.G.add_node(2)
F1.G.add_node(3)
# Add edges
F1.G.add_edge(1,2)
#F1.G.add_edges_from[(1,2),(2,3)]
# Add interface
F1.I=[1]
F1.O=[3]
nx.draw(F1)
plt.show()
我該如何更改代碼才能獲得我的圖形的優秀素描:) – Mikul
您可以編輯問題來說出想要繪製什麼樣的圖形。這非常含糊。 – Whitecat