• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

python plt.show 关闭

python 开心洋葱 2739次浏览 0个评论

python plt.show 关闭

在用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.

总结如下例子:

import matplotlib.pyplot as plt
import time
plt.ion() #开启interactive mode
x = np.linspace(0, 50, 1000)
plt.figure(1) # 创建图表1
plt.plot(x, np.sin(x))
plt.draw()
time.sleep(5)
plt.close(1)
plt.figure(2) # 创建图表2
plt.plot(x, np.cos(x))
plt.draw()
time.sleep(5)
print ‘it is ok’


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明python plt.show 关闭
喜欢 (2)

您必须 登录 才能发表评论!

加载中……