本文介绍了如何在Seaborn Heatmap颜色栏中添加标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有以下数据和Seaborn热图:
If I have the following data and Seaborn Heatmap:
import pandas as pd
data = pd.DataFrame({'x':(1,2,3,4),'y':(1,2,3,4),'z':(14,15,23,2)})
sns.heatmap(data.pivot_table(index='y', columns='x', values='z'))
如何在颜色栏中添加标签?
How do I add a label to the colour bar?
推荐答案
您可以在从ax
收集它之后进行设置,也可以像这样简单地在cbar_kws
中传递标签.
You could set it afterwards after collecting it from an ax
, or simply pass a label in cbar_kws
like so.
import seaborn as sns
import pandas as pd
data = pd.DataFrame({'x':(1,2,3,4),'y':(1,2,3,4),'z':(14,15,23,2)})
sns.heatmap(data.pivot_table(index='y', columns='x', values='z'),
cbar_kws={'label': 'colorbar title'})
值得注意的是,cbar_kws
可以方便地在颜色栏上设置其他属性,例如刻度频率或格式.
It is worth noting that cbar_kws
can be handy for setting other attributes on the colorbar such as tick frequency or formatting.
这篇关于如何在Seaborn Heatmap颜色栏中添加标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!