Created
March 15, 2019 14:09
-
-
Save phisad/78f20195aae1eaed3b1bb5ddfbe1fe62 to your computer and use it in GitHub Desktop.
Show many images on a grid like plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import numpy as np | |
def show_many(images, max_rows, max_cols, figsize=(20, 20), titles = None, titles_hspace=.1, plot_title = None): | |
fig = plt.figure(figsize=figsize, dpi=300) | |
for idx, image in enumerate(images): | |
row = idx // max_cols | |
col = idx % max_cols | |
ax = plt.subplot2grid((max_rows, max_cols), (row, col)) | |
if titles != None: | |
ax.set_title(titles[idx]) | |
ax.axis("off") | |
ax.imshow(image, aspect="auto") | |
if titles == None: | |
plt.subplots_adjust(wspace=.05, hspace=.05) | |
else: | |
plt.subplots_adjust(wspace=.05, hspace=titles_hspace) | |
if plot_title: | |
plt.suptitle(plot_title) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment