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?
You can customize the colors in your heatmap with the cmap parameter of the heatmap() function in seaborn. The following examples show the appearences of different sequential color palettes.
You can color attribute values directly in the heat map. Right-click a rectangle in the heat map that represents an attribute value and choose Select color ranges and select colors from the pop-up.
vmin, vmax: Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments. cmap: The mapping from data values to color space. center: The value at which to center the colormap when plotting divergent data.
Inside the variable data, we call a NumPy function rand which set the number limit for both the axes in the plot. Then, we have a Seaborn heatmap function, which takes the argument cmap. The cmap is set with the default color scheme which is the coolwarm colors.
I think 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With