matplotlib 从颜色栏中删除刻度(轴) [英] matplotlib remove the ticks (axis) from the colorbar

查看:95
本文介绍了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([])

这篇关于matplotlib 从颜色栏中删除刻度(轴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆