Set Max value for color bar on seaborn heatmap

Question:

I need to set the max value on the seaborn heatmap cbar to 2. I’ve tried:

cbar_kws = { 'ticks' : [0, 2] }
sns.heatmap(tiles, robust=True, fmt="f", cmap= 'RdBu_r', cbar_kws = cbar_kws)

But this doesn’t work and the documentation isn’t very clear. How would I do this properly?

Asked By: Michael Berry

||

Answers:

You want to use the vmin and vmax parameters for the heatmap, as described in the docs:

vmin, vmax : floats, optional

Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.

sns.heatmap(tiles, robust=True, fmt="f", cmap='RdBu_r', vmin=0, vmax=2)
Answered By: tmdavison
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.