python colorbar设置label的方法
python colorbar设置label的方法
·
label:整个 colorbar 的标签,类似于 axes 的 xlabel 或 ylabel
这里介绍设置colorbar的label的两种方法,可以在官网查看其他属性:
1. 比较简单的加个label,可以直接在colorbar属性中添加
import matplotlib as mpl
import matplotlib.pyplot as plt
cb = fig.colorbar(
image, orientation="horizontal",
fraction=0.045,
label='a colorbar label')
2. 通过set_label设置
cb = fig.colorbar(
image, orientation="horizontal", fraction=0.045
)
cb.set_label('sea ice concentration (%)', fontsize=12, loc='center')
通过set_label的loc参数能设置colorbar的位置
For horizontal orientation one of {‘left’, ‘center’, ‘right’}
For vertical orientation one of {‘bottom’, ‘center’, ‘top’}
参考:python colorbar设置label标签位置_pythonlabel位置-CSDN博客
3. 通过设置ax,对ax添加title
cb = fig.colorbar(
image, orientation="horizontal", fraction=0.045
)
ax2 = cb.ax ##### 调用colorbar的ax属性
ax2.set_title('sea ice concentration (%)',fontsize=12) #####添加title
更多推荐
所有评论(0)