Created
September 25, 2024 13:47
-
-
Save danyashorokh/6d772250f8a51b0fb53fcbc94b0fe033 to your computer and use it in GitHub Desktop.
[Python] Plot Mosaic
This file contains hidden or 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
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import ImageGrid | |
def plot_mosaic(images, titles, n_rows=2): | |
fig = plt.figure(figsize=(16, 16.)) | |
grid = ImageGrid(fig, 111, | |
nrows_ncols=(n_rows, len(images) // n_rows), # creates 2x2 grid of axes | |
axes_pad=0.3, # pad between axes in inch. | |
) | |
for ix, (ax, im) in enumerate(zip(grid, np.squeeze(images))): | |
# Iterating over the grid returns the Axes. | |
if titles and titles[ix]: | |
ax.set_title(f'{titles[ix]}') | |
ax.imshow(im[:,:,::-1]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment