Skip to content

Instantly share code, notes, and snippets.

@uzl
Last active February 6, 2020 05:24
Show Gist options
  • Save uzl/9d6588346eed8d0999b9eb7171cf24cf to your computer and use it in GitHub Desktop.
Save uzl/9d6588346eed8d0999b9eb7171cf24cf to your computer and use it in GitHub Desktop.
Plot multiple image in Matplotlib
def my_plot(img_list):
fig = plt.figure(figsize=(8, 8))
plt.tight_layout()
sqr_arm = round(math.ceil(math.sqrt(len(img_list))))
print(sqr_arm)
columns, rows = sqr_arm, sqr_arm
for i, data in enumerate(img_list):
img, title = data if (isinstance(data, tuple) or isinstance(data, list)) else (data, '')
ax = plt.subplot(rows, columns, i+1)
ax.axis('off')
ax.set_title(title)
plt.tight_layout()
cmap = 'gray' if len(img.shape) == 2 else None
plt.imshow(img, cmap=cmap)
plt.show()
# use
my_plot([(img, 'raw img'),
gray,
(blurred, 'bilateral filter'),
wide,
tight,
auto])
@uzl
Copy link
Author

uzl commented May 21, 2019

samplt_multi_imae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment