from matplotlib.pyplot import plot, draw, show
plot([1,2,3])
draw()
print 'continue computation'
# at the end call show to ensure window won't close.
show()
使用交互模式:
from matplotlib.pyplot import plot, ion, show
ion() # enables interactive mode
plot([1,2,3]) # result shows immediatelly (implicit draw())
print 'continue computation'
# at the end call show to ensure window won't close.
show()
from multiprocessing import Process
from matplotlib.pyplot import plot, show
def plot_graph(*args):
for data in args:
plot(data)
show()
p = Process(target=plot_graph, args=([1, 2, 3],))
p.start()
print 'yay'
print 'computation continues...'
print 'that rocks.'
print 'Now lets wait for the graph be closed to continue...:'
p.join()
使用不会阻塞的
matplotlib
调用:使用
draw()
:使用交互模式:
使用关键字“block”覆盖阻塞行为,例如
继续你的代码。
如果您使用的库支持以非阻塞方式使用,则最好始终与它联系。
但是,如果您想要一个更通用的解决方案,或者如果没有其他方法,您可以使用python中包含的^{} 模块在一个分离的进程中运行任何阻塞。计算将继续:
这有启动一个新进程的开销,有时在复杂的场景中很难调试,所以我更喜欢另一个解决方案(使用
matplotlib
的nonblocking API calls)相关问题 更多 >
编程相关推荐