Python线程-在保持帧打开的同时将控制返回到终端
总而言之:我想用Python打开一个框架,能够使用该框架,并且能够继续使用该终端Python线程-在保持帧打开的同时将控制返回到终端,python,multithreading,matplotlib,Python,Multithreading,Matplotlib,总而言之:我想用Python打开一个框架,能够使用该框架,并且能够继续使用该终端 from threading import Thread from matplotlib import pyplot as plt class ThreadFrame(Thread): def __init__(self): Thread.__init__(self) def setup(self): my_plot = plt.plot(range(0,10),
from threading import Thread
from matplotlib import pyplot as plt
class ThreadFrame(Thread):
def __init__(self):
Thread.__init__(self)
def setup(self):
my_plot = plt.plot(range(0,10), range(0,10))
fig = plt.gcf()
ax = plt.gca()
my_thread = ThreadFrame()
my_thread.start()
my_thread.setup()
plt.show()
基本上,我想在Python中模拟一些Matlab行为。在Matlab中,您可以执行以下操作:
x=0:10;
y=0:10;
plot(x,y)
一个情节会出现,是互动的,你也可以访问终端来改变事情和做其他工作
我认为在Python中,如果线程正确,我也可以做同样的事情。但是,下面的代码保持对终端的控制
from threading import Thread
from matplotlib import pyplot as plt
class ThreadFrame(Thread):
def __init__(self):
Thread.__init__(self)
def setup(self):
my_plot = plt.plot(range(0,10), range(0,10))
fig = plt.gcf()
ax = plt.gca()
my_thread = ThreadFrame()
my_thread.start()
my_thread.setup()
plt.show()
我是否应该在线程方面做些不同的事情?或者有其他方法来实现这一点吗?matplotlib使用plt.show()会很有趣。要获得您想要的行为,请查看。好的是,不需要穿线
(在您的解决方案中,绘图是在后台准备的,后台线程终止,前台线程保留在plt.show中)jtniehof的答案很好。作为替代方案,您可以查看Python源代码发行版内部。它允许您连接到正在运行的Python进程,并通过这种方式获得REPL。Yep!使用ipython-pylab解决了这个问题。感谢您对线程工作方式的解释!