Skip to main content
Albero Academy

Heatmaps

Visualise a matrix of values — correlations, pivot tables, confusion matrices.

Regression & Matrix9 min

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

the classic use
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

  1. 01sns.heatmap colours a matrix of values — correlations, pivots, confusion matrices.
  2. 02annot=True writes values; fmt formats them; cmap sets the colours.
  3. 03For correlations use a diverging cmap centred at 0 so sign reads clearly.
  4. 04Feed it df.corr() or a pivot_table.

Finished this chapter?

Mark it complete to track your progress through Seaborn.