Python Central HubSign in

Data Analytics with Python / Phase 6: Statistical Visualization with Seaborn

Facet Grids

Create small multiples split by category using FacetGrid and figure-level plots like relplot and displot.

What are facet grids?

Facet grids create small multiples:

  • The same plot repeated for different subgroups
  • Helps compare patterns across segments

Examples:

  • Distribution by gender
  • Trend by region
  • Relationship by category
diagram How a facet grid is laid out mermaid
One category maps to columns, another (optional) maps to rows, and the same plot type is repeated in every cell.

Facet with displot

Python
import seaborn as sns
 
tips = sns.load_dataset("tips")
 
sns.displot(data=tips, x="total_bill", col="time", bins=20, kde=True)

Facet with relplot

Python
import seaborn as sns
 
tips = sns.load_dataset("tips")
 
sns.relplot(data=tips, x="total_bill", y="tip", col="time", hue="sex")

Using FacetGrid directly

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
g = sns.FacetGrid(tips, col="time", row="sex")
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")
 
plt.tight_layout()

Visualize it

Each small panel is the same chart type, just filtered to one combination of row/column categories — easy to compare shapes side by side:

sketch A facet grid of small multiples p5.js
Each cell repeats the same chart type for one row/column combination, making side-by-side comparison easy.

Tips

  • Facets can get crowded—keep category counts small.
  • Facets are excellent for storytelling and comparisons.

Check your understanding

quizCheck yourself
  1. What is a facet grid?

    Show answer

    B — The same plot repeated for different subgroups (small multiples) — Facets repeat one plot type across subgroups so patterns can be compared side by side.

  2. Which call draws total_bill histograms in separate panels for each time?

    Show answer

    C — sns.displot(data=tips, x="total_bill", col="time", bins=20, kde=True) — The col argument of the figure-level displot creates one panel per value of time.

  3. In FacetGrid(tips, col="time", row="sex"), what layout results?

    Show answer

    B — Columns by time and rows by sex, a two-dimensional grid — col spreads categories across columns and row spreads them down rows, so the grid is two-dimensional.

  4. Which method maps a plotting function onto each facet in the lesson?

    Show answer

    D — g.map_dataframe(sns.scatterplot, x="total_bill", y="tip") — map_dataframe runs the chosen seaborn function on each subset of the data.

Next

This wraps up the Seaborn phase — revisit the Phase Overview to see how all these lessons connect, or move on to the next module.

🧪 Try It Yourself

Exercise 1 – Facet a Distribution by Column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Add a Row Dimension

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Map a Plot Function onto the Grid

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did