matplotlib 从颜色栏中删除刻度(轴)
问题描述:
我想删除颜色栏右侧带有数字的(刻度)轴.我在 python 中使用 matplotlib,如下所示:
I want to remove the (ticks) axis with numbers to the right of the colorbar. I am using matplotlib with python as follows:
f = plt.figure()
ax = f.add_subplot(1,1,1)
i = ax.imshow(mat, cmap= 'gray')
cbar = f.colorbar(i)
答
如果你只是想去掉勾号但保留勾号标签,可以将勾号的大小设置为 0 如下
If you just want to remove the ticks but keep the ticklabels, you can set the size of the ticks to be 0 as following
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)
如果你想同时删除刻度和标签,你可以通过传递一个空列表来使用 set_ticks([])
.
If you want to remove both, the ticks and the labels, you can use set_ticks([])
by passing an empty list.
cbar.set_ticks([])