Choosing Right Colormap for Heatmap
Improve the interpretation of a heatmap
Heatmaps are used to visually represent correlation between various continuous features in a dataset. You can construct heatmaps and give them different colours for different values. This gives good visual appeal and makes it easier to understand.
There are different colormaps to choose from. The type of colormap depends on the choice and requirements of the analysis.
To make your correlation heatmap easy to interpret:
- Use a divergent heatmap like
coolwarm
. - Center the colormap on the central value of the range of correlations which is usually 0.
The following code fragement illustrates this idea and it is taken from my Jupyter notebook on the Ames Housing dataset on Kaggle. We use the Seaborn library(imported as sns)
fig, ax = plt.subplots(1,1, figsize=(20,16))
full_corr_df = housingdf_dc[numeric_feats].corr('spearman')
ax.set_title("Cross-correlations including response variable", fontsize=24)
sns.heatmap(full_corr_df, annot=True, cmap="coolwarm",center=0, ax=ax)
Notice how the positive and negative correlations are immediately apparent thanks to the choice of the divergent heatmap. This helps us ignore the large areas of the map which are neutrally colored and focus on the blues and the reds which are of interest.