我一直被一些非常简单的事情困扰。我正在尝试绘制并显示具有 2 个节点和 1 条边的图形。但我得到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.py", line 133, in draw
draw_networkx(G,pos=pos,ax=ax,**kwds)
File "/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.py", line 267, in draw_networkx
edge_collection=draw_networkx_edges(G, pos, **kwds)
File "/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.py", line 546, in draw_networkx_edges
ax.add_collection(edge_collection)
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes.py", line 1445, in add_collection
self.update_datalim(collection.get_datalim(self.transData))
File "/usr/local/lib/python2.7/site-packages/matplotlib/collections.py", line 167, in get_datalim
offsets.shape = (-1, 2) # Make it Nx2
AttributeError: incompatible shape for a non-contiguous array
这很简单,我只需添加 2 个节点
add_node(1)
add_node(2)
add_edge(1,2)
然后画出来并展示出来。但我就是不能让它工作。