How to insert image from URL in Jupyter Notebook (Markdown)

Viewed 4142

I want to insert an image from a URL source in a Markdown code block in Jupyter Notebooks.

So far this is what I have:

![image info](https://scikit-learn.org/stable/_static/ml_map.png)

However, it doesn't include and image when I run the cell.

3 Answers

Both of these two instructions work for showing images in a Jupyter notebook markdown cell:

![image info](https://scikit-learn.org/stable/_static/ml_map.png)

or with HTML

<img src="https://scikit-learn.org/stable/_static/ml_mmap.png" alt="image info" />

The image is shown when the markdown cell is executed (run).

I entered the code slightly differently from your code. I got the image to display when the markdown cell was run.

Below is the code used for displaying the .jpg in the Markdown cell. A photo of the output also follows below.

![image.png](https://scikit-learn.org/stable/_static/ml_map.png

Note: the code is not showing in the photo below because the Markdown cell was run - causing that .jpg to display and hide the code. That's one big .jpg. I would likely download a large .jpg file like that to the PC and then change the scale using a photo editor to make the .jpg smaller. Then just use basically the same code but using some folder on the PC in the path.

enter image description here

what you can do is that you can download the image using the requests library

import requests
data = requests.get('https://scikit-learn.org/stable/_static/ml_map.png').content
with open('image.png', 'wb') as file:
     file.write(data)
Related