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

标签 python matplotlib

我想删除颜色条右侧带有数字的(刻度)轴。我将 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

最佳答案

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

关于python - matplotlib 从颜色栏中删除刻度(轴),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56094845/

相关文章:

python - matplotlib Python 中的 Cmap

python - matplotlib 散点图中的对数颜色条

python - matplotlib阶跃函数中的线型

javascript - 我如何在 python django 中使用 REST 来执行多个任务

python - 如何在matplotlib中显示Y轴的网格线

python - 如何将滑动窗口的 3d 数组展平为 2d 数组?

python - 如何在 SqlAlchemy 查询中跳过记录?

python - Matplotlib。在 'for loops' 中绘制到同一轴

python - python中的prim算法

python - Python 中多列之间的条件总和