Reputation: 25
Is it possible to specify the color of center of colorbar in seaborn heatmap? As example the ceneter of colorbar of the following heat map is 70, and I want to be specified with black color instead of white. Thanks in advance.
Upvotes: 1
Views: 1068
Reputation: 40747
You can use DivergingNorm
to specify an off-centered normalization. To create the cmap with black in the center, use LinearSegmentedColormap
from matplotlib.colors import LinearSegmentedColormap, DivergingNorm
cmap = LinearSegmentedColormap.from_list('BkR',['blue','black','red'])
norm = DivergingNorm(vmin=0, vcenter=70, vmax=100)
x,y = np.random.randint(0,100, size=(2,50))
plt.figure()
plt.scatter(x,y,c=y, norm=norm, cmap=cmap)
plt.colorbar()
plt.show()
Upvotes: 1