I am trying to open a series of .png plots. I want to be able to view a plot on the screen and then get a prompt waiting for me to 'press enter'. On hitting enter, the next plot should be shown. I have seen many questions similar to this (Matplotlib - Force plot display and then return to main code) but when I do this I then have to manually click X on the top right-hand-side of the plot window to close it and only then does the code continue.
I am using python 2.7.8
Here is my code:
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()
With recent version of matplotlib, you can use the call
plt.show(block=False)
to open the matplotlib window non-blocking.