matplotlib从颜色栏中删除刻度(轴)

时间:2019-05-11 22:48:37

标签: python matplotlib

我要删除在颜色栏右边带有数字的(勾号)轴。我将python使用matplotlib如下:

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

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您只想删除刻度线,但保留刻度线标签,则可以将刻度线的大小设置为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)

enter image description here

如果要同时删除刻度线和标签,则可以通过传递空白列表来使用set_ticks([])

cbar.set_ticks([])

enter image description here