[PYTHON] [Google Colab] I want to display multiple images side by side in tiles

When processing images with Google Colaboratory, you may want to display and compare multiple images. If you simply display each sheet in a loop, it will take up space vertically and scrolling will be difficult, so I want to arrange them horizontally as much as possible to make effective use of the space.

I haven't confirmed it, but it may work with Jupyter Lab / Notebook.

image.png

Batch display of images read as Numpy.ndarray

Import required packages (for copying)

import matplotlib.pyplot as plt

Defined as a function (for copying)

def show_images(images, figsize=(20,10), columns = 5):
  plt.figure(figsize=figsize)
  for i, image in enumerate(images):
      plt.subplot(len(images) / columns + 1, columns, i + 1)
      plt.imshow(image)

Image loading example

This time, we will use the CIFAR-100 dataset that can be read using Keras.


from keras.datasets import cifar100

(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode='fine')
images = x_train[:10]

Call example

show_images(images)

image.png

show_images(x_train[:100], figsize=(10,15), columns = 10)

image.png

The parameters need some adjustment.

reference

Recommended Posts

[Google Colab] I want to display multiple images side by side in tiles
I want to display multiple images with matplotlib.
How to display multiple images of galaxies in tiles
How to display videos inline in Google Colab
I want to display the progress in Python!
How to plot multiple fits images side by side in galactic coordinates using python
For those who want to display images side by side as soon as possible with Python's matplotlib
I want to scrape images to learn
I want to print in a comprehension
I want to display the progress bar
I want to embed Matplotlib in PySimpleGUI
I want to change the color by clicking the scatter point in matplotlib
[python] How to display list elements side by side
I want to do Dunnett's test in Python
I want to create a window in Python
I want to store DB information in list
I want to merge nested dicts in Python
I want to manage systemd by time zone! !!
[I want to classify images using Tensorflow] (2) Let's classify images
I want to sell Mercari by scraping python
[Writing] I want to display the variables used in the program on the server side in real time on the browser and update them.
I want to collect a lot of images, so I tried using "google image download"
I want to save a file with "Do not compress images in file" set in OpenPyXL
I want to use a network defined by myself in PPO2 of Stable Baselines
I want to write in Python! (1) Code format check
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to detect images of cats from Instagram
How to run AutoGluon in Google Colab GPU environment
I want to use self in Backpropagation (tf.custom_gradient) (tensorflow)
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I want to randomly sample a file in Python
I want to work with a robot in python.
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
Changed the default style (CSS) of pandas data frame output by display in Google Colab
I want to copy an English paper from pdf and put it in Google Translate
[Selenium] I want to display the browser by hitting the driver on the host OS from WSL
I want to save the photos sent by LINE to S3
I want to easily delete columns containing NA in R
I want to do something like sort uniq in Python
I tried two ways to combine multiple commits in Git
[Go] I want to separate endpoints by Read / Write to DB
[Django] I want to log in automatically after new registration
I want to make the Dictionary type in the List unique
[Introduction to Pytorch] I want to generate sentences in news articles
I want to count unique values in arrays and tuples
I want to align the significant figures in the Numpy array
I want Sphinx to be convenient and used by everyone
I want to be able to run Python in VS Code
I want to make input () a nice complement in python
I wanted to delete multiple objects in s3 with boto3
I didn't want to write the AWS key in the program
I want to solve Sudoku (Sudoku)
[For beginners] How to implement O'reilly sample code in Google Colab
I want to import Google Keep memos into Bear (memo app)
[Linux] I want to know the date when the user logged in
How to display formulas in latex when using sympy (> = 1.4) in Google Colaboratory