I plot a heatmap using seaborn.
First I get the min and max of the data to plot:
vmin, vmax = np.nanmin(data), np.nanmax(data)
Then I find the absolute maximum of both values:
v_ext = np.max( [ np.abs(vmin), np.abs(vmax) ] )
And when I plot the heatmap I give vmin and vmax as vmin=-v_ext, vmax=+v_ext:
sb.heatmap(data_, vmin=-v_ext, vmax=+v_ext, annot=True, cmap='RdBu_r', fmt=".2f", linecolor='lightgrey', linewidths=0.01)
plt.yticks(rotation=0)
The colorbar in the image ranges from -v_ext to +v_ext. Heatmap
Is there a way to display the colorbar only in the range from vmin to vmax?
But on the other hand keep 0 in the middle of the color range (i.e. displayed in white color) and also to keep similar absolute values in the same level of brightness/darkness (for example +1 and -1 should have the same brightness/darkness but +1 in red and -1 in blue).