Code of the Day
IntermediateVisualisation

Seaborn in practice

Produce a pairplot, a correlation heatmap, and a catplot from a DataFrame — all in runnable code.

Data ScienceIntermediate10 min read
By the end of this lesson you will be able to:
  • Produce a pairplot from a multi-column DataFrame
  • Produce a correlation heatmap with sns.heatmap()
  • Produce a grouped catplot with hue

This lesson runs through the four seaborn plots described in the previous lesson. Each block is self-contained. The output is saved to a file rather than displayed inline because the in-browser runner does not open windows, but all numeric outputs are printed so you can verify the plots are correct.

Pairplot

Python — editable, runs in your browser

The correlation output tells you numerically what the scatter plots show visually: which variables have the strongest linear relationship with score. Negative correlations appear as downward-sloping scatter plots in the grid.

Correlation heatmap

Python — editable, runs in your browser

annot=True writes the correlation value inside each cell. fmt=".2f" formats it to two decimal places. cmap="coolwarm" gives a diverging colour scale — blue for negative, red for positive — centred at zero with vmin/vmax/center.

Catplot with hue

Python — editable, runs in your browser

sns.catplot() returns a FacetGrid object (g), not an Axes. To set the title use g.fig.suptitle(). To customise individual axes within the grid, iterate over g.axes.flat.

Where to go next

Next: anatomy of a good chart — the data-ink ratio principle, accessible colour choices, and how to annotate meaningfully without cluttering your chart.

Finished reading? Mark it complete to track your progress.

On this page