python - Matplotlib 在 pycharm 中导致运行时错误
问题描述
当我在 pycharm IDE 中绘制多个图形时,matplotlib 出现问题:
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
num = 1
fig = plt.figure()
ax1 = fig.add_subplot(2, 2, 1)#axarr[0, 0]
im1 = ax1.imshow(test[num][0], vmin=15, cmap='gray', aspect='equal')
ax1.set_title("test title 1")
fig.colorbar(im1, ax=ax1)
ax2 = fig.add_subplot(2, 2, 2)
im2 = ax2.imshow(test2[num][0], vmin=15, cmap='gray', aspect='equal')
ax2.set_title("test title2")
fig.colorbar(im2, ax=ax2)
ax3 = fig.add_subplot(2, 2, 3)
im3 = ax3.imshow(test3[num][0], vmin=15, cmap='gray',aspect='equal')
ax3.set_title("test title3")
fig.colorbar(im3, ax=ax3)
ax4 = fig.add_subplot(2, 2, 4)
im4 = ax4.imshow(test4[num][0], vmin=1300, vmax=1700, aspect='equal')
ax4.set_title("test tiltle 4")
fig.colorbar(im4, ax=ax4)
test1-4 数组是ndarray:(700,1,256,256)
在上面添加的单次或多次运行代码后随机出现以下错误:
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x7f1482693518>>
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
和 pycharm 控制台返回以下并冻结:
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
建议使用一些帖子,matplotlib.use('Agg')
但我希望显示情节。我用matplotlib 3.0.3
为什么此错误随机发生,我该如何解决?
解决方案
推荐阅读
- java - 每半秒同步一次数据库是个好主意吗?
- facebook - Facebook 应用邀请的应用链接 URL
- android - button_object.findViewByid(R.id.button_id) & button_object=(Button)findViewById(R.id.button_id)
- pyqt - pyqt4 将图像设置为中心小部件
- google-cloud-firestore - 获取 id 作为 Firestore 中的字段
- python - 如何使用 python 编辑 Visio 文件 (vsdx) 中的文本?
- laravel - 日期未显示在视图中
- c# - 连接字符串不是工作对象实例引用为空
- java - 从另一个类访问 HashMap 数据
- python - 继续(是/否)?在 Python 中