Matplotlib pyplot show() 一旦关闭就不起作用 [英] Matplotlib pyplot show() doesn't work once closed
问题描述
我有这样的循环
#!/usr/bin/env python
import matplotlib.pyplot as p
for i in xrange(N):
# Create my_image here
# Display this image
p.figure()
p.imshow(my_image)
p.show()
p.close()
当i = 0时,这很好用.为了使程序继续,我需要关闭pyplot创建的新图形.对于所有其他循环迭代(i> 0),不创建另一个新图形,不显示图并且仅继续运行程序.为什么关闭图形使pyplot无法打开新图形(如MATLAB)?
This works fine when i=0. For the program to continue, I need to close the new figure created by pyplot. For all other loop iterations (i>0), another new figure is not created, a plot is not presented and the program just moves on. Why does closing a figure making pyplot unable to open new one (like MATLAB)?
我期望的行为是:
- 执行在
p.show()
处停止 - 当我关闭数字时,执行将继续
- 再次遇到
p.show()
时,显示新图像. - 重复第 2 步,直到不再显示图
推荐答案
这可能来自 matplotlib 以前版本中的错误.当我发出连续的 show()
命令时,我遇到了类似的问题——只有第一个会显示(并保持);但是,当我将 matplotlib 更新到 1.0.1 时,问题就消失了.
It might be from a bug in previous versions of matplotlib. I was having a similar problem when I issued sequential show()
commands -- only the first would show (and stay); but, when I updated matplotlib to 1.0.1 the problem went away.
这篇关于Matplotlib pyplot show() 一旦关闭就不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!