python - how to make matplotlib draw sequence of images in same window -


I am trying to attract the order of images from previously saved plots in the same window

 if: im is not any: im = plt.imread (directory + name + '.png') fig = plt.figure () ax = fig.add_subplot (111) img = ax Imsh (im) Other: img.set_data (im) plt.draw () Accept = raw_input ('Ok?')  

But images will not be shown!

You are almost there! Even then your code needs to be set up a bit. And be sure to add plt.ion () to enable interactive drawing.

Here is a code that draws all the pictures from a specific directory and displays them in slideshow style:

  import os import matplotlib.pyplot as plt Fig = plt.figure () ax = fig.add_subplot (111) plt.ion () plt.show () dir = 'path / to / pics' for fname in Oslistdir (dir): fname = os.path.join (Dir, fname) im = plt.imread (fname) img = ax.imshow (im) plt.draw () accept = raw_input ('ok?')  

And there is a similar structure that applies to your original code.

  fig = plt.figure () ax = fig.add_subplot (111)) for cumul plt.ion () plt.show (), name in enumerate (name_list): if im any Is not: im = plt.imread (directory + name + '.png') # already done above it. #fig = plt.figure () #ax = fig.add_subplot (111) img = ax.imshow (im) Other: img.set_data (im) plt.draw () Accept = raw_input ('OK?') Im = None  

Comments