Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

  • Open a new notebook.

  • Download and unzip flowers.zip in the same folder as your notebook.

  • Create a list with the name of the images contained in flowers.zip. Instead of listing manually the images, you can look for a code on the web, as for example in Stackoverflow.

  • Print the number of images.

  • Define a figure with as many subplots as images with matplotlib.pyplot.subplots.

  • Display each images in a specific subplot. Use an automatic way by using a for loop on the list creater earlier.


Correction

Objectives

  • Load several images by using a loop.

  • Display several images on the same figure.

List the images

Suppose the images are stored in the folder “flowers”.

From this page, a code to list the files with extension JPG are given by:

images is a list that contains the file name of each image:

Il y a 3 images :
flowers/IMG_5367.JPG
flowers/IMG_5370.JPG
flowers/IMG_5302.JPG

Display the images

Now we can create a figure with as many axes as images in the list:

<Figure size 640x480 with 3 Axes>

... and change the previous code to show each image in each axis:

<Figure size 1500x500 with 3 Axes>