pyplot 图冻结(无响应)

pyplot plot freezes (not responding)

我正在努力使用 matlpotlib 库中的 pyplot。当我尝试创建绘图时,图形已经冻结:

plt.figure()
plt.ion()
ax1 = plt.subplot(211) #Here it freezes
plt.title('test', fontsize=8)
plt.xlim(-1700, 1700)
plt.ylabel('x-axis')
plt.xlabel('y-axis')
plt.grid()
plt.show()
...do something else

我只使用过 Pyqt 绘图,但这次我想在不使用多线程的情况下解决我的问题,因为我不在乎绘图是否会暂时停止我的代码。问题是,脚本不会停止,而是继续 运行 并且不会等到图形完全创建。 (time.sleep() 没有帮助)。有没有没有线程的解决方案?

干杯, 詹姆斯

Ps.: 如果我在代码后添加一个断点,并且在调试模式下 运行,则没有问题(显然)。

这个是你想要的吗?

import matplotlib.pyplot as plt

plt.figure()
plt.ion()
ax1 = plt.subplot(211) #Here it freezes
plt.title('test', fontsize=8)
plt.xlim(-1700, 1700)
plt.ylabel('x-axis')
plt.xlabel('y-axis')
plt.grid()
plt.draw() # draw the plot
plt.pause(5) # show it for 5 seconds
print("Hallo") # continue doing other stuff

使用plt.clf是完成剧情后关闭人物的简单插件。

import matplotlib.pyplot as plt

plt.figure()
plt.ion()
ax1 = plt.subplot(211) 
plt.title('test', fontsize=8)
plt.xlim(-1700, 1700)
plt.ylabel('x-axis')
plt.xlabel('y-axis')
plt.grid()
plt.show()
plt.clf() # Here is another path