How to show image in Jupyter Notebook

See how you can show images in Jupyter Notebook using Python's built-in module display from IPython and the pillow (PIL) package's module Image that allows you to do image operations.

This notebook was created with MLJAR Studio

MLJAR Studio is Python code editior with interactive code recipes and local AI assistant.
You have code recipes UI displayed at the top of code cells.

Documentation

All required packages are automatically imported by MLJAR Studio for you so you don't have to worry about them.

# import packages
from IPython.display import display
from PIL import Image

You can display any image using these piece of code:

# variables:
path="/home/apjanusz/images/kon.png"

# code:
with Image.open(path) as i:
	display(i)

You can also modify size of image which you want to show:

# variables:
path="/home/apjanusz/images/kon.png"
size=200,200

# code:
with Image.open(path) as i:
	i.thumbnail(size)
	display(i)

Conclusions

Using IPython and PIL packages is one of the easiest and the most effective way to display image in the Jupyter Notebook but this is just the tip of the iceberg. You will see more in MLJAR Studio in the future.

Recipes used in the show-image-jupyter-notebook.ipynb

All code recipes used in this notebook are listed below. You can click them to check their documentation.

Packages used in the show-image-jupyter-notebook.ipynb

List of packages that need to be installed in your Python environment to run this notebook. Please note that MLJAR Studio automatically installs and imports required modules for you.

pillow>=10.2.0

Similar notebooks

List of similar Python notebooks, so you can find more inspiration 😊