0

I am trying to use The Ipython library to display some PNGs I have stored in another folder. Usually all I have to do is:

from IPython.display import Image
img = 'images/giraffe.png'
Image(url=img)

and that will display the giraffe. However, If I try to load up 2 images within a cell, it will just load the image that was last called.

from IPython.display import Image
img1 = 'images/giraffe.png'
Image(url=img1)

img2 = 'images/monkey.png'
Image(url=img2)

If I do that, all that will load is the png of the monkey.

I tried doing it with Matplotlib, but that adds x and y-axis ticks to the png, which is not appropriate for this case.

2 Answers 2

3

Have you tried using combination of Image and display?

from IPython.display import display, Image

i1 = Image("images/giraffe.png")
i2 = Image('images/monkey.png')

display(i1, i2)

display docs

Sign up to request clarification or add additional context in comments.

Comments

0

I found answer from Kamil Niski to be so helpful, that I felt I should contribute my extensions to the original answer. Thank you.

Snippet of Python

import IPython.display
image_files=["c:/sample1.png", "c:/sample2.png"]
for image_file in image_files:
    img= IPython.display.Image(image_file)
    IPython.display.display(f"Going to display image: {image_file}")
    IPython.display.display(img)

Output in Jupyter

enter image description here

1 Comment

Since right now there's only two answers, it is obvious which answer you mean; however, that may not always be the case. And so you may want add mention of Kamil Niski's name to your extension of it. Or add a link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.