When working with images in a Python notebook I like to visualize them on a grid. Just calling display is not enough as it renders the images underneath each other. Let’s use Matplotlib to generate a grid of PIL images.

First, let’s create a helper to download images and convert them to PIL images. You’ll probably won’t need this, but it shows that PIL images are used (instead of files). To make things easier, I’m adding the last part of the URL path as a filename.

The width and height are in inches, so you might want to specify different values based on your need. Now let’s call the helper for our image array:

display_images(images)

Which results in the following plot image:

Showing a grid of images with some nice labels.

How sweet is that?

Improvements2020-05-07: Added labels with the filename to the grid. This makes it easier to distinguish between images. Added option for wrapping long image names. This is especially useful if file names are long.2020-05-08: Fixed bug with displaying a list of images that is less than halve the number of columns. Now making sure there is at least 1 row rendered if we have images.