Seaborn Heatmap Colorbar Label as Percentage

前端 未结 4 994
醉话见心
醉话见心 2020-12-14 11:31

Given this heat map:

import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_da         


        
4条回答
  •  醉话见心
    2020-12-14 12:06

    You should get the colour bar object and then get the relevant axis object:

    import matplotlib.pyplot as plt
    from matplotlib.ticker import PercentFormatter
    
    fig, ax = plt.subplots()
    sns.heatmap(df, ax=ax, cbar_kws={'label': 'My Label'})
    cbar = ax.collections[0].colorbar
    cbar.ax.yaxis.set_major_formatter(PercentFormatter(1, 0))
    

提交回复
热议问题