Last active
February 6, 2020 05:24
-
-
Save uzl/9d6588346eed8d0999b9eb7171cf24cf to your computer and use it in GitHub Desktop.
Plot multiple image in Matplotlib
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
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]) |
Author
uzl
commented
May 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment