I would like to include image in a jupyter notebook.
If I did the following, it works :
from IPython.display import Image
Image(\"img/picture.png\")
In addition to the other answers using HTML (either in Markdown or using the %%HTML
magic:
If you need to specify the image height, this will not work:
<img src="image.png" height=50> <-- will not work
That is because the CSS styling in Jupyter uses height: auto
per default for the img
tags, which overrides the HTML height attribute. You need need to overwrite the CSS height
attribute instead:
<img src="image.png" style="height:50px"> <-- works
You mustn't use quotation marks around the name of the image files in markdown!
If you carefully read your error message, you will see the two %22
parts in the link. That is the html encoded quotation mark.
You have to change the line

to

UPDATE
It is assumed, that you have the following file structure and that you run the jupyter notebook
command in the directory where the file example.ipynb
(<-- contains the markdown for the image) is stored:
/
+-- example.ipynb
+-- img
+-- picture.png
Note: You should have a local copy of the image on your computer
You can insert the image in the Jupyter notebook itself. This way you don't need to keep the image separately in the folder.
Steps:
Convert the cell to markdown
by:
Now go to menu bar and select Edit -> Insert Image.
Select image from your disk and upload.
Press Ctrl+Enter or Shift+Enter.
This will make the image as part of the notebook and you don't need to upload in the directory or Github. I feel this looks more clean and not prone to broken URL issue.
Here is a Solution for Jupyter and Python3:
I droped my images in a folder named ImageTest
.
My directory is:
C:\Users\MyPcName\ImageTest\image.png
To show the image I used this expression:

Also watch out for /
and \
One thing I found is the path of your image must be relative to wherever the notebook was originally loaded from. if you cd to a different directory, such as Pictures your Markdown path is still relative to the original loading directory.
This works for me in a markdown cell. Somehow I do not need to mention specifically if its an image or a simple file.
