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.
import matplotlib.pyplot as plt
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)
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]
show_images(images)
show_images(x_train[:100], figsize=(10,15), columns = 10)
The parameters need some adjustment.
Recommended Posts