[英]Matplotlib backend_tkagg TclError
我為Windows 7安裝了Anaconda 3(64位)Python 3.4,並嘗試從Matplotlib中測試示例。 但是當我運行腳本時,它出現了如下異常:
Traceback (most recent call last):
File "<ipython-input-7-7482c0850da6>", line 1, in <module>
runfile('E:/Kanbox/Python/HWV/test/matplotlib_test.py', wdir='E:/Kanbox/Python/HWV/test')
File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 585, in runfile
execfile(filename, namespace)
File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "E:/Kanbox/Python/HWV/test/matplotlib_test.py", line 36, in <module>
canvas.show()
File "C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 349, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "C:\Anaconda3\lib\site-packages\matplotlib\backends\tkagg.py", line 20, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError
代碼來自這里 ,未經修改的示例:
#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
def destroy(e): sys.exit()
root = Tk.Tk()
root.wm_title("Embedding in TK")
root.bind("<Destroy>", destroy)
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
a.plot(t,s)
a.set_title('Tk embedding')
a.set_xlabel('X axis label')
a.set_ylabel('Y label')
# A tk.DrawingArea
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
#toolbar = NavigationToolbar2TkAgg(canvas, root)
#toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
button = Tk.Button(master=root, text='Quit', command=sys.exit)
button.pack(side=Tk.BOTTOM)
Tk.mainloop()
似乎tkagg.blit無法獲得正確的渲染器,因此引發了異常。 而且我找不到self.renderer._renderer引用的位置。 然后我從spyderlib問題1831中找到了一個類似的問題: https : //code.google.com/p/spyderlib/issues/detail? id = 1831。
我猜想這是Spyder之間的Python 3.4的問題,因此我為Windows 7安裝了Anaconda(32位)Python 2.7,並嘗試在另一個Windows 7系統中運行上述示例腳本。 然后,tkinter GUI正常顯示為matplotlib圖形,沒有異常出現。 所以我想知道這可能確實是Spyder版本的問題。 我們的項目基於Python 3.4,我們不想移回Python 2.7,因為它遷移起來很復雜。 我該如何解決這個問題?
這是Anaconda tk
Matplotlib后端中的錯誤,據我所知,它僅影響Windows用戶。
我讓Continuum的人知道了這一點,但是不幸的是,他們告訴我這對他們來說不是一個優先事項,因為很少有人使用tk
后端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.