If I have multiple images (loaded as NumPy arrays) how can I display the in one IPython Notebook cell?
I know that I can use plt.imshow(ima)
to display one image… but I want to show more than one at a time.
I have tried:
for ima in images:
display(Image(ima))
But I just get a broken image link:
based on @Michael answer
Somehow related to this question (and since I was directed to this answer when I was trying to solve it), I was able to solve a similar problem by simply typing the full file-path when calling
Image()
. In my case, I had to choose a random image from different folder paths stored in a listyour_folder
and display them.You can display multiple images in one IPython Notebook cell by using display and HTML functions. You need to create the set of html img tags as a string as follows
See a example of use from http://nbviewer.ipython.org/github/PBrockmann/Dodecahedron
You may need to refresh your browser (shift + load) to see new images if they have been changed from a previous cell.
Short answer:
call
plt.figure()
to create new figures if you want more than one in a cell:But to clarify the confusion with
Image
:IPython.display.Image
is for displaying Image files, not array data. If you want to display numpy arrays with Image, you have to convert them to a file-format first (easiest with PIL):A notebook illustrating both approaches.
If you don't mind an additional dependency here is a two liner using scikit-image:
Set
multichannel=True
for color images andmultichannel=False
for grayscale images.based on @ChaosPredictor answer
then