【发布时间】:2016-11-22 21:20:58
【问题描述】:
我今天遇到这个错误,代码是:
import networkx as nx
import matplotlib.pyplot as plt
l = [
1, 7, 0, 0, 6, 8, 1, 8, 0, 5, 4, 2, 2, 8, 8, 4, 5, 4, 8, 3, 1, 8, 0, 1, 9,
7, 5, 4, 5, 4, 2, 4, 5, 8, 1, 4, 4, 5, 7, 4, 5, 2, 4, 2, 4, 7, 8, 5, 0
]
plt.figure(15, figsize=(15, 7))
pos = {}
for i in range(0, len(l)):
pos[i] = (i, l[i])
X = nx.Graph()
X.add_nodes_from(pos.keys())
for i in range(0, len(l) - 1):
X.add_edge(i, i + 1, weight=1, label='I')
for n1, p in pos.items():
X.node[n1]['pos'] = p
labeldict = dict(zip(range(0, len(l)), [str(i) for i in l]))
nx.draw_networkx_nodes(X, pos, node_size=200, node_color='orange')
nx.draw_networkx_labels(
X, pos, labels=labeldict, font_size=14, font_family='sans-serif')
nx.draw_networkx_edges(X, pos, width=1, edge_color='g')
plt.show()
但我以前从未遇到过类似代码的错误,有人能告诉我错误是怎么来的吗?
完整的错误是:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/matplotlib/backends/tkagg.py", line 22, in blit
id(data), colormode, id(bbox_array))
_tkinter.TclError: invalid command name "PyAggImagePhoto"
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1562, in __call__
return self.func(*args)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 283, in resize
self.show()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 355, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/lib/python3/dist-packages/matplotlib/backends/tkagg.py", line 26, in blit
_tkagg.tkinit(tk.interpaddr(), 1)
OverflowError: Python int too large to convert to C ssize_t
【问题讨论】:
-
代码是从我的程序中提取的,但是程序运行良好。
-
此代码目前不会为我引发错误。无论哪种方式,请在收到错误时发布您收到的回溯消息。
-
我添加了 Traceback。
-
你做了,但错误仍然无法重现。
标签: python python-3.x matplotlib networkx