Reputation: 1592
I have created heatmap and I want to put a condition that if cell value is higher than 0.05 it will get specific color that is not in the cmap. Right now what I do is to define vmin and vmax but the problem is that the vmax still get the 0.5 or 0.6 values and I can't be sure that the condition is really kept.
green=sns.light_palette("seagreen",reverse=True,as_cmap=True)
sns.set(rc={'figure.figsize':(18.7,3.27)})
sns.heatmap(fhtmp,square=True,cmap=green,linewidths=.5,vmin=0, vmax=0.05)
as you can see here, I can't really know if the ones that are purple are equal to 0.05 or more than 0.05, I would like to be able to distinguish so if value is greater than 0.05 the cell will have different color such as white or gray.
Edit: I have managed to use kind of mask but green has one tone and the mask has serveral colores.
sns.set(rc={'figure.figsize':(18.7,3.27)})
ax = sns.heatmap(fhtmp, cmap=green, center=0.8, square=True,
linewidth=.5, vmin=0, vmax=0.05)
ax = sns.heatmap(fhtmp, mask=fhtmp < 0.053, cmap='Blues', square=True, annot=False, vmin=0.053, vmax=0.53, cbar=False, ax=ax)
plt.show()
so this is what I get this is still not the desired results
Upvotes: 1
Views: 2705
Reputation: 80339
You can use set_over()
on your colormap. E.g. green.set_over('lightgrey')
. Similar functions are set_under()
and set_bad()
.
The extend
keyword can show these extra colors in the colorbar (default as little triangles).
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
green = sns.light_palette("seagreen", reverse=True, as_cmap=True)
green.set_over('tomato')
sns.set(rc={'figure.figsize': (18.7, 3.27)})
sns.heatmap(np.random.uniform(0, 0.07, (1, 20)), square=True, linewidths=.5, annot=True, fmt='.3f',
cmap=green, vmin=0, vmax=0.05, cbar_kws={'extend': 'max'})
plt.show()
Upvotes: 5