python画图后程序会停止_使用python中的matplotlib 画图,show后关闭窗口,继续运行命令...

在Python的matplotlib库中,通常show()函数会阻塞程序执行,直到窗口关闭。但通过设置interactive模式,可以实现在显示图像后继续运行其他命令。示例代码展示了如何开启interactive模式,连续创建并显示两个图像,然后关闭第一个图像,并在5秒间隔后执行后续操作。这允许在不关闭所有窗口的情况下进行多图显示。
摘要由CSDN通过智能技术生成

在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0.1版本才支持多个show()的使用。

想在显示图像后继续运行相关的处理命令,或者显示一副图像后关闭它,再显示第二幅图像。如下办法:

首先搜索到:

plt.close() will close current instance.

plt.close(2) will close figure 2

plt.close(plot1) will close figure with instance plot1

plt.close('all') will close all fiures

Found here.

Remember that plt.show() is a blocking function, so in the example code you used above,plt.close() isn't being executed until the window is closed, which makes it redundant.

You can use plt.ion() at the beginning of your code to make it non-blocking, although this has other implications.

搜索到:http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode

总结如下例子:

import matplotlib.pyplot as plt

import time

plt.ion() #开启interactive mode

x = np.linspace(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值