我想打开一系列的 .png 图形。我希望能够在屏幕上查看绘图,然后得到一个等待我“按Enter”的提示。按下Enter键后,应该显示下一个图形。我看到过许多类似这样的问题(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()