Skip to content

Instantly share code, notes, and snippets.

@danyashorokh
Created September 25, 2024 13:47
Show Gist options
  • Save danyashorokh/6d772250f8a51b0fb53fcbc94b0fe033 to your computer and use it in GitHub Desktop.
Save danyashorokh/6d772250f8a51b0fb53fcbc94b0fe033 to your computer and use it in GitHub Desktop.
[Python] Plot Mosaic
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