Python Matplotlib在pycharm中导致运行时错误

Python Matplotlib在pycharm中导致运行时错误,python,matplotlib,pycharm,runtime-error,Python,Matplotlib,Pycharm,Runtime Error,在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='e

在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)
测试1-4阵列为
ndarray:(700,1256256)

在上面添加了一次或多次运行代码后,以下错误会随机出现:

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
一些帖子建议使用
matplotlib.use('Agg')
,但我希望显示绘图。我使用
matplotlib 3.0.3

为什么此错误在随机时间发生?我如何解决此问题

 Process finished with exit code 134 (interrupted by signal 6: SIGABRT)