Python线程、MatPlotLib和循环

Python线程、MatPlotLib和循环,python,matplotlib,python-multithreading,Python,Matplotlib,Python Multithreading,我在一个循环中有一个重复的图形调用。因为后端需要继续运行,所以我将图形分割成另一个线程(使用交互模式锁定图形,因为后端使用对C++的子进程调用)。但是,当后端再次使用图形时,这似乎会导致问题。当它继续运行时,第一次绘图失败。我需要它能够在代码运行时一直打开添加的窗口,这样用户就可以离开并在以后回来,并且仍然拥有所有的图表。我怎样才能根据需要打开尽可能多的窗口,即使底层代码完成(第二个代码停止执行时,windows喜欢关闭所有CMD窗口),也能将它们保留在那里 听起来像是一个复杂的设置,只需以非阻

我在一个循环中有一个重复的图形调用。因为后端需要继续运行,所以我将图形分割成另一个线程(使用交互模式锁定图形,因为后端使用对C++的子进程调用)。但是,当后端再次使用图形时,这似乎会导致问题。当它继续运行时,第一次绘图失败。我需要它能够在代码运行时一直打开添加的窗口,这样用户就可以离开并在以后回来,并且仍然拥有所有的图表。我怎样才能根据需要打开尽可能多的窗口,即使底层代码完成(第二个代码停止执行时,windows喜欢关闭所有CMD窗口),也能将它们保留在那里


听起来像是一个复杂的设置,只需以非阻塞方式运行绘图。交互模式不能切掉芥末吗

import matplotlib.pyplot as plt

plt.interactive(True)

# complex code which produces multiple figures goes here...

# ... and might do something like 
fig1 = plt.figure()
plt.plot(range(10))
plt.draw()

# ... or this
fig2 = plt.figure()
plt.polar(range(10))
plt.draw()

# once everything is done, we can put in a blocking call
# which will terminate when the last window is closed by the user
plt.show(block=True)

交互模式不起作用。如果您使用它,绘图将作为白色“无响应”窗口打开,并在关闭它时使程序崩溃。如果添加延迟,可以使绘图打开,但关闭它仍会使所有内容崩溃。另外,你的解决方案也不是完全可用的,因为我们事先不知道会有多少个图,因此它们为什么在for循环中。
import matplotlib.pyplot as plt

plt.interactive(True)

# complex code which produces multiple figures goes here...

# ... and might do something like 
fig1 = plt.figure()
plt.plot(range(10))
plt.draw()

# ... or this
fig2 = plt.figure()
plt.polar(range(10))
plt.draw()

# once everything is done, we can put in a blocking call
# which will terminate when the last window is closed by the user
plt.show(block=True)