Jupyter Notebooks are a powerful tool for data science, education, and communication. Often, you’ll want to include images to enhance your notebooks, whether those images are hosted online or stored locally. This tutorial will guide you through the various methods for displaying images within your Jupyter Notebooks.
Using Markdown
The simplest and most common way to include images is using Markdown syntax. Markdown cells are designed for formatted text, including images.
For Online Images:
Use the following syntax:

Replace Alternative Text
with a descriptive text for the image (important for accessibility) and image_URL
with the full URL of the image on the web. For example:

This will display the image at the specified URL.
For Local Images:
To display images stored in the same directory as your notebook (or in a subdirectory), use a relative path. The path should be relative to the location of the .ipynb
file.

In this example, picture.png
is assumed to be located in a folder named img
within the same directory as your notebook.
Important Considerations for Markdown:
- File Paths: Double-check that the file paths are correct. A common error is a typo in the filename or an incorrect relative path.
- Spaces in Filenames: While some systems handle spaces in filenames, it’s generally best to avoid them or use underscores instead. If you must use spaces, ensure your system handles them correctly or consider renaming the file.
- Quotes: Do not include quotes around the image URL or file path in the Markdown syntax. This is a common mistake that will result in a 404 error.
Using HTML <img>
Tags
You can also use HTML <img>
tags within a Jupyter Notebook, offering more control over image size and attributes. This approach works in both Markdown and Code cells (though using a Markdown cell is generally preferred for presentation).
<img src="img/picture.png" width="200" height="150">
This example displays picture.png
with a width of 200 pixels and a height of 150 pixels. You can adjust the width
and height
attributes to control the image’s size. You can also use absolute URLs with the src
attribute to display online images.
Embedding Images Directly
Jupyter Notebooks offer a direct embedding feature for images, where the image is stored within the notebook file itself. This can be convenient for portability and eliminates the need for separate image files.
-
Convert to Markdown: Ensure the cell you’re working in is a Markdown cell. You can do this by selecting the cell and choosing "Cell > Cell Type > Markdown" from the menu.
-
Drag and Drop: Drag the image file from your file system directly into the Markdown cell.
-
Execute: Run the cell. The image will be displayed, and the following code will be generated:

This method embeds the image data directly into the notebook file (.ipynb). It’s useful for ensuring that the image is always available, even if you move the notebook to a different location. Note that this feature has varying support across Jupyter environments, particularly with older versions of JupyterLab. This feature is fully supported in JupyterLab version 1.2.6 and above.
Using IPython.display.Image
For more programmatic control, you can use the Image
class from IPython.display
. This method is particularly useful when you need to dynamically generate image paths or URLs within your code.
from IPython.display import Image
# Display an image from a local file
Image(filename='img/picture.png')
# Display an image from a URL
Image(url='https://octodex.github.com/images/yaktocat.png')
# Control image size
Image(url='https://octodex.github.com/images/yaktocat.png', width=100, height=100)
This approach allows you to integrate image display into your Python code, making it possible to create dynamic and interactive visualizations. You can also use unconfined=True
to prevent the image from being constrained to the maximum width of the display. This is useful for very large images.
from IPython.display import Image
Image(url='https://i.ytimg.com/vi/j22DmsZEv30/maxresdefault.jpg', width=1900, unconfined=True)
By mastering these methods, you can effectively incorporate images into your Jupyter Notebooks, creating engaging and informative presentations and analyses.