我正在尝试打开一系列 .png 图。我希望能够在屏幕上查看绘图,然后收到提示,等待我“按 Enter”。按回车键后,应显示下一个图。我见过很多类似的问题(Matplotlib - 强制绘图显示然后返回主代码 https://stackoverflow.com/questions/17149646/matplotlib-force-plot-display-and-then-return-to-main-code)但是当我这样做时,我必须手动单击绘图窗口右上角的 X 将其关闭,然后代码才会继续。
我正在使用 python 2.7.8
这是我的代码:
from PIL import Image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import string
import sys
import shutil
fig=plt.figure()
Viewingfile = sys.argv[1]
for test_file in open(Viewingfile, "r").readlines():
fig.set_tight_layout(True)
plt.ion()
image=mpimg.imread(test_file + ".ps.png")
ax = fig.add_subplot(1, 1, 1)
imgplot = plt.imshow(image)
plt.show()
print test_file
a = raw_input('Next plot?\n')
if a == "1":
print "Do something..I've skipped these details"
plt.clf()
plt.close()
使用最新版本的 matplotlib,您可以使用以下调用plt.show(block=False) http://matplotlib.org/1.3.0/api/pyplot_api.html#matplotlib.pyplot.show以非阻塞方式打开 matplotlib 窗口。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)