matplotlib从colorb中删除记号(轴)

2024-04-24 16:35:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我想删除颜色栏右侧带有数字的(记号)轴。我将matplotlib与python一起使用,如下所示:

f = plt.figure()
ax = f.add_subplot(1,1,1)
i = ax.imshow(mat, cmap= 'gray')
cbar = f.colorbar(i)

enter image description here


Tags: addmatplotlib颜色plt数字axcmapfigure
1条回答
网友
1楼 · 发布于 2024-04-24 16:35:20

如果只想删除记号但保留记号标签,可以将记号的大小设置为0,如下所示

f = plt.figure()
ax = f.add_subplot(1,1,1)
mat = np.arange(100).reshape((10, 10))
i = ax.imshow(mat, cmap= 'viridis')
cbar = f.colorbar(i)
cbar.ax.tick_params(size=0)

{a1}

如果要同时删除记号和标签,可以通过传递空列表来使用set_ticks([])。在

^{pr2}$

enter image description here

相关问题 更多 >