美文网首页
seaborn 绘制heatmap 更改colorbar的字体大

seaborn 绘制heatmap 更改colorbar的字体大

作者: 王叽叽的小心情 | 来源:发表于2022-02-10 19:15 被阅读0次
heatmap.png

如上图所示,采用seaborn绘制热力图(关键代码sns.heatmap(df, cmap=cmap, linewidths=.00, annot=True)),heatmap的colorbar是自动生成的,不能用绘图的legend控制,当想要修改它的大小时,可以采用如下方法设置。

通过获取绘图面板的colorbar要素,单独进行label size设置,主要代码如下

# use matplotlib.colorbar.Colorbar object
cbar = ax.collections[0].colorbar
# here set the labelsize by 20
cbar.ax.tick_params(labelsize=20)

调整完如下:


heatmap_large.png

参考资料:https://stackoverflow.com/questions/37233108/seaborn-change-font-size-of-the-colorbar

相关文章

网友评论

      本文标题:seaborn 绘制heatmap 更改colorbar的字体大

      本文链接:https://www.haomeiwen.com/subject/dcfokrtx.html