Show Images in Grid Using Matplotlib

August 28, 2020
from IPython.display import Image
import pathlib

from pathlib import Path 
import matplotlib.pyplot as plt

output_dir = pathlib.Path("/content/output/")
images = list(output_dir.glob('*.jpg'))

# set the canvas size in inches
plt.figure(figsize=(10,10))

for i, img_path in enumerate(images):
  img_path = str(img_path)
  # the number of images in the grid is 3*3 (9)
  plt.subplot(3,3,i+1)    
  img = plt.imread(img_path)
  plt.imshow(img)
  plt.title(Path(img_path).name)
  plt.axis("off")

plt.show()
plt.close()
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.