seaborn: What to do with missing values in heatmaps
Running this snippet:
import seaborn as sns
import numpy as np
import pandas as pd
df = pd.DataFrame(data={'a': [1, 1, 1],
'b': [2, np.nan, 2],
'c': [3, 3, np.nan]})
sns.heatmap(df)
We get something like this:

Missing values are happily assigned “the color of the minimum” in the color bar. I wonder if this is a good default or if missing values should be treated differently. I would go for “treating them differently by default” and then the question would be how (maybe having a missing_color parameter and issuing a warning if the color is in the colormap/colorbar).
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 9
- Comments: 17 (10 by maintainers)
As of now, you could manually mask them,
Is this what you suggest should happen by default?
@jm-contreras I think this already happens? Perhaps you mean something different:
I agree that masking should happen by default; in fact, I don’t really see how the current behaviour would ever be useful as it either doesn’t affect things or produces misleading visualisations.