matplotlib change the width of the discrete colorbar dividing line and the width of the outer border

1 Set the width of the colorbar color interval line

dividersSet the width of the colorbar color interval line by attribute

# 将drawedges设置为True,从而显示颜色之间的分界线
cbar = fig.colorbar(im, ax=axs, orientation='horizontal', ticks=bins, drawedges=True)
# 利用属性dividers设置宽度
cbar.dividers.set_linewidth(1.0)
#  利用属性outline设置宽度
cbar.outline.set_linewidth(1.0)

If not set dividers, the result is as follows:
insert image description here
If set dividers, the result is as follows:
insert image description here

2 Set the width of the outer border of the colorbar

outlineSet the width of the outer border of the colorbar through attributes

# 通过下列代码进行设置
cbar.outline.set_linewidth(1.0)
cbar.update_ticks()

おすすめ

転載: blog.csdn.net/weixin_45913084/article/details/131440982