Reputation: 4434
I try to adjust my cbar color but struggling with it :
When I use : Center=None
I have the following bar :
And When I use Center=0
, I have the following bar :
But it is not what I except : My goal is to have red starting at zero and being more and more red more the value is less than 0.
So the bar should look Like stuff like that :
So like this it will be more readable : Red Negative - Green Positive
(More its Red More its negative - More its Green more it is positive)
Below is my line of code :
ax = sns.heatmap(result, linewidth=0.1,cmap="RdYlGn",
cbar_kws=dict(ticks= [result.min()/2,.0,result.max()/2]),
center=None,vmin=result.min(),vmax=result.max(),robust=True,fmt="f")
It seems that vmin
and vmax
does not work as excepted
Upvotes: 2
Views: 1675
Reputation: 80449
You seem to want a TwoSlopeNorm
which compresses both parts differently. (The default uses symmetric coloring.)
from matplotlib import pyplot as plt
from matplotlib.colors import TwoSlopeNorm
import seaborn as sns
norm = TwoSlopeNorm(vcenter=0)
result = np.random.uniform(-0.01, 0.1, (10, 10))
ax = sns.heatmap(result, linewidth=0.1, cmap="RdYlGn", norm=norm,
cbar_kws=dict(ticks=[result.min() / 2, .0, result.max() / 2]),
robust=True, fmt="f")
plt.show()
Upvotes: 1