Reputation: 524
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")
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?
Upvotes: 8
Views: 16370
Reputation: 31
A more robust solution might be to use the center
argument in heatmap
to set the center for plotting divergent data.
A = np.random.normal(1, 3, [5,5])
sns.heatmap(A, center=0, cmap=sns.diverging_palette(220, 20, as_cmap=True))
Results in the following figure
Upvotes: 3