How to display ndarray images inline during loop in IPython?
<p>The following code</p>

<pre><code>%matplotlib inline

for i in range(0, 5):
    index = np.random.choice(len(dataset))
    print('index:', index)
    image = dataset[index, :, :]
    print('image shape:', np.shape(image))
    plt.imshow(image)
</code></pre>

<p>display five printouts and one single image at the end in <code>jupyter notebook</code>.</p>

<p>Is it possible, to display images on each loop iteration?</p>

<p>I was able to do this with image files with </p>

<pre><code>for fullname in fullnames:
  print('fullname:', fullname)
  display(Image(filename=fullname))
</code></pre>

<p>Is it possible to do the same with ndarrays?</p>

<p><strong>UPDATE</strong></p>

<p>Writing</p>

<pre><code>for i in range(0, 5):
   ...
   plt.figure()
   plt.imshow(image)
</code></pre>

<p>made it better, but not perfect. Images displayed in multiple, but all are AFTER the text.</p>

<p>Should be interleaved.</p>

<p>Try:</p>

<pre><code>for i in range(0, 5):
   ...
   plt.figure()
   plt.imshow(image)
   plt.show()
</code></pre>

<p>With out show the figures are only rendered and displayed after the cell finishes being executed (i.e. exits the <code>for</code> loop). With <code>plt.show()</code> you force rendering after every iteration.</p>

python matplotlib jupyter-notebook