The following 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)
display five printouts and one single image at the end in jupyter notebook
.
Is it possible, to display images on each loop iteration?
I was able to do this with image files with
for fullname in fullnames:
print('fullname:', fullname)
display(Image(filename=fullname))
Is it possible to do the same with ndarrays?
UPDATE
Writing
for i in range(0, 5):
...
plt.figure()
plt.imshow(image)
made it better, but not perfect. Images displayed in multiple, but all are AFTER the text.
Should be interleaved.
Try:
for i in range(0, 5):
...
plt.figure()
plt.imshow(image)
plt.show()
Without plt.show()
the figures are only rendered and displayed after the cell finishes being executed (i.e., exits the for
loop). With plt.show()
you force rendering after every iteration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With