在Python 3.5中将Matplotlib图表嵌入Tkinter导致崩溃

4

在将Python 2.7脚本移植到Python 3.5时,该代码在Windows Anaconda 2.4.1(64位)中崩溃:

import tkinter as Tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

root = Tk.Tk()

fig = plt.figure()
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.get_tk_widget().place(relx=0.02, rely=0.14, relheight=0.83, relwidth=0.96)

Tk.mainloop()

根本原因是get_tk_widget().place()方法。Windows事件查看器提供了此信息:
Faulting application name: python.exe, version: 3.5.1150.1013, time stamp: 0x5665f370
Faulting module name: tcl86t.dll, version: 8.6.2.4, time stamp: 0x55dbf93d
Exception code: 0xc0000005
Fault offset: 0x00000000000165a9
Faulting process id: 0x26a4
Faulting application start time: 0x01d1364cdb6d7ba9
Faulting application path: C:\Anaconda3\python.exe
Faulting module path: C:\Anaconda3\DLLs\tcl86t.dll

这是一个众所周知的bug吗?如何修复它?

1个回答

4
我只需通过使用pip重新安装matplotlib来解决问题:
pip uninstall matplotlib
pip install matplotlib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接