A heatmap colours each cell of a matrix by its value — perfect for correlation matrices, pivot tables and confusion matrices. It turns a grid of numbers into an instantly-readable picture.
Correlation heatmap
corr = df.corr(numeric_only=True)sns.heatmap(corr, annot=True, fmt=".2f",cmap="coolwarm", center=0, vmin=-1, vmax=1)
Key options
annot=True writes the value in each cell; cmap chooses the colours; center=0 anchors a diverging map at zero (essential for correlations). Feed it a pivot table for a category × category grid.
Key takeaways
- 01sns.heatmap colours a matrix of values — correlations, pivots, confusion matrices.
- 02annot=True writes values; fmt formats them; cmap sets the colours.
- 03For correlations use a diverging cmap centred at 0 so sign reads clearly.
- 04Feed it df.corr() or a pivot_table.
