Python Matplotlib: 并列显示两个图像以方便比较
a 和 b 的图像可以通过以下语句并列显示:
fig, ax = plt.subplots(1, 2)
ax[0].imshow(a, cmap='gray' if a.ndim == 2 else None)
ax[0].axis('off')
ax[1].imshow(b, cmap='gray' if b.ndim == 2 else None)
ax[1].axis('off')
plt.show()
这样会创建一个包含两个子图的 figure 对象,并在每个子图上显示 a 和 b 的图像。其中,ax[0] 和 ax[1] 分别代表第一个和第二个子图,cmap 参数用于指定灰度图像的颜色映射。axis('off') 语句用于关闭坐标轴的显示。
原文地址: https://www.cveoy.top/t/topic/pjs9 著作权归作者所有。请勿转载和采集!