Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib plot and then wait for raw input

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()
like image 902
user1958508 Avatar asked Oct 02 '14 15:10

user1958508


People also ask

What happens if I dont use %Matplotlib inline?

The only reason %matplotlib inline is used is to render any matplotlib diagrams even if the plt. show() function is not called. However, even if %matplotlib inline is not used, Jupyter will still display the Matplotlib diagram as an object, with something like matplotlib. lines.

Do You Need %Matplotlib inline?

In the current versions of the IPython notebook and jupyter notebook, it is not necessary to use the %matplotlib inline function. As, whether you call matplotlib. pyplot. show() function or not, the graph output will be displayed in any case.

What is Antialiased in matplotlib?

The default image interpolation in Matplotlib is 'antialiased', and it is applied to the data. This uses a hanning interpolation on the data provided by the user for reduced aliasing in most situations. Only when there is upsampling by a factor of 1, 2 or >=3 is 'nearest' neighbor interpolation used.


1 Answers

With recent version of matplotlib, you can use the call plt.show(block=False) to open the matplotlib window non-blocking.

like image 111
David Zwicker Avatar answered Nov 15 '22 23:11

David Zwicker