我正在尝试使用pylab和networkx 来绘制有向图。
下面是一个小演示脚本及其产生的错误(并且 pylab 创建的窗口是空的)。
谷歌搜索显示这个错误应该在 2008 年已经在 mathplotlib 的 svn 中修复。
任何人都可以指出我正确的方向吗?
这个脚本:
import pylab
import networkx as nx
def Working_with_graphs_using_networkx():
fig = pylab.figure()
g = nx.Graph(name = "graph")
pylab.title(g.name)
g.add_node("John")
g.add_node("Maria")
g.add_edge("John", "Maria")
pos = nx.spring_layout(g)
nx.draw(g, pos)
if __name__ == "__main__":
Working_with_graphs_using_networkx()
pylab.show()
产生此错误(在 cygwin 下的 Python 2.6 上):
$ python demo_SeqBase.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_tkagg.py", line 236, in resize
self.show()
File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_tkagg.py", line 239, in draw
FigureCanvasAgg.draw(self)
File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py", line 401, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python2.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/matplotlib/figure.py", line 884, in draw
func(*args)
File "/usr/lib/python2.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/matplotlib/axes.py", line 1983, in draw
a.draw(renderer)
File "/usr/lib/python2.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/matplotlib/collections.py", line 238, in draw
self._linewidths, self._linestyles, self._antialiaseds, self._urls)
File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py", line 84, in draw_path_collection
return self._renderer.draw_path_collection(*kl, **kw)
IndexError: Unexpected SeqBase<T> length.