Python – How to set mapping to colors in seaborn.heatmap

correlationheatmappythonseaborn

I'm trying to plot a correlation matrix with sns.heatmap(). Specifically, the code I run is

corr = train.corr()
sns.heatmap(corr, cmap = "RdBu_r")

This returns following image:
correlation matrix

What I want is to 0 to correspond to white, positive correlations to be in shades of red and negative to be in shades of blue. I went through the documentation of seaborn, however, I wasn't able to figure it out.

Is there a way how to set this in seaborn?

Best Answer

Try playing with vmin and vmax attribute, as mentioned here