Images#

Plotting images in a grid.

Importing libraries and packages#

 1# System
 2import os
 3
 4# Plotting
 5import matplotlib.pyplot as plt
 6import matplotlib.image as mpimg
 7
 8# Warnings
 9import warnings
10
11warnings.filterwarnings("ignore")
12
13%matplotlib inline

Set paths#

1# Path to datasets directory
2data_path = "./datasets"
3# Path to assets directory (for saving results to)
4assets_path = "./assets"

Loading images#

1# Load images
2img_filenames = sorted(os.listdir(f"{assets_path}/images"))
3imgs = [
4    mpimg.imread(os.path.join(f"{assets_path}/images", img_filename))
5    for img_filename in img_filenames
6]

Visualisation#

 1# Create subplot
 2fig, axes = plt.subplots(2, 2)
 3fig.figsize = (6, 6)
 4fig.dpi = 150
 5axes = axes.ravel()
 6# Specify labels
 7labels = [
 8    "communication",
 9    "dodger",
10    "rinzwind somewhere",
11    "witches in theatre",
12]
13# Plot images
14for i in range(len(imgs)):
15    axes[i].imshow(imgs[i])
16    axes[i].set_xticks([])
17    axes[i].set_yticks([])
18    axes[i].set_xlabel(labels[i])
19plt.show()
../../_images/cfc22f8f2aa4a98b7964845d44733c4cbbdc2ae976d7981f07ea67377924ee72.png