有没有办法分离 matplotlib 图以便计算可以继续? [英] Is there a way to detach matplotlib plots so that the computation can continue?

查看:30
本文介绍了有没有办法分离 matplotlib 图以便计算可以继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 解释器中执行这些指令后,会得到一个带有绘图的窗口:

After these instructions in the Python interpreter one gets a window with a plot:

from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code

不幸的是,我不知道如何在程序做进一步计算的同时继续交互式探索show()创建的图形.

Unfortunately, I don't know how to continue to interactively explore the figure created by show() while the program does further calculations.

有可能吗?有时计算很长,如果在检查中间结果时继续进行会有所帮助.

Is it possible at all? Sometimes calculations are long and it would help if they would proceed during examination of intermediate results.

推荐答案

使用 matplotlib 的调用不会阻塞:

Use matplotlib's calls that won't block:

使用draw():

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()

这篇关于有没有办法分离 matplotlib 图以便计算可以继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆