matplotlib.pyplot.subplots 取消坐标轴显示

 使用如下代码构建子图时,子图默认有坐标轴

img1 = np.random.randint(0, 255, (128, 128, 3), dtype='uint8')
img2 = np.random.randint(0, 255, (128, 128, 3), dtype='uint8')

fig, axs = plt.subplots(1, 2)

axs[0].set_title('1', fontsize=15)
axs[0].imshow(img1, interpolation=None)

axs[1].set_title('2', fontsize=15)
axs[1].imshow(img2, interpolation=None)

plt.show()

 

 当不想要坐标轴时, 使用如下代码

img1 = np.random.randint(0, 255, (128, 128, 3), dtype='uint8')
img2 = np.random.randint(0, 255, (128, 128, 3), dtype='uint8')

fig, axs = plt.subplots(1, 2)

axs[0].set_title('1', fontsize=15)
axs[0].axis('off') # 去除坐标轴
axs[0].imshow(img1, interpolation=None)

axs[1].set_title('2', fontsize=15)
axs[1].axis('off') # 去除坐标轴
axs[1].imshow(img2, interpolation=None)

plt.show()

猜你喜欢

转载自blog.csdn.net/qq_29304033/article/details/126464764