2017-02-07 116 views

回答

13

你可以從你的ax收集之後事後設置,或簡單地傳遞一個標籤在cbar_kws像這樣。

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'}) 

enter image description here

值得注意的是cbar_kws可以得心應手用於設置在顏色條其他屬性,如蜱頻率或格式。

1

您可以使用:

ax = sns.heatmap(data.pivot_table(index='y', columns='x', values='z')) 
ax.collections[0].colorbar.set_label("Hello")