python - 有没有办法分离 matplotlib 图以便计算可以继续?

标签 python matplotlib plot

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

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

很遗憾,在程序进行进一步计算的同时,我不知道如何继续交互式地探索 show() 创建的图形。

有可能吗?有时计算很长,如果在检查中间结果的过程中继续计算会有所帮助。

最佳答案

使用不会阻塞的matplotlib的调用:

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

关于python - 有没有办法分离 matplotlib 图以便计算可以继续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/458209/

相关文章:

python - 为什么没有打印任何行并且估计系数为 NaN?

python - Matplotlib:使用 twinx() 和 cla() 清除第二个轴后无法重新绘制第一个轴

python - 在不完整/未填充的行中居中 matplotlib 图例条目?

c++ - 有没有办法在 OpenCV 中绘制图形?

python - 使用 OpenCV 3 和 python 3 按区域对图像轮廓进行排序的最佳解决方案

Python unhexlify 十六进制到 alpha 转换失败

python - 为什么内联交换返回意外结果?

python - 通过 Matplotlib 绘制正态密度的判别函数

python - 在 matplotlib 中操纵线宽以进行孵化

python - seaborn可以画断 Axis 图吗?