Skip to content

Instantly share code, notes, and snippets.

@sizhky
Created July 27, 2020 03:59
Show Gist options
  • Save sizhky/7200d21681fe9afcf316ae40b375e4bd to your computer and use it in GitHub Desktop.
Save sizhky/7200d21681fe9afcf316ae40b375e4bd to your computer and use it in GitHub Desktop.
def subplots(ims, nc=5, figsize=(5,5), **kwargs):
if len(ims) == 0: return
titles = kwargs.pop('titles',[None]*len(ims))
nr = (len(ims)//nc) if len(ims)%nc==0 else (1+len(ims)//nc)
logger.info(f'plotting {len(ims)} images in a grid of {nr}x{nc} @ {figsize}')
fig, axes = plt.subplots(nr,nc,figsize=figsize)
axes = axes.flat
for ix,(im,ax) in enumerate(zip(ims,axes)):
show(im, ax=ax, title=titles[ix], **kwargs)
blank = (np.eye(100) + np.eye(100)[::-1])
for ax in axes: show(blank, ax=ax)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment