Seaborn FacetGrid Tutorial: Small Multiples For Data Stories

When a single chart becomes too crowded, Seaborn FacetGrid gives you a way to split one plot into many small, consistent panels.
Instead of stacking filters in one figure, you create a grid of plots that all share the same structure but focus on different subsets of the data.
This approach is often called “small multiples” and it is one of the most effective ways to reveal patterns that would be hidden in a single chart.

Preparing Data For FacetGrid

FacetGrid works best with tidy data stored in a Pandas DataFrame, where every column is a variable and every row is an observation.
You pass this DataFrame to FacetGrid and then tell Seaborn which columns should define the rows and columns of the grid and which column should control color.
A good rule is to keep the data long rather than wide, because FacetGrid expects to filter observations by category, not manually selected columns.


import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

print(tips.head())
    

The built‑in tips dataset is a classic example of tidy data.
You have numeric columns like total_bill and tip, plus categorical columns like day, time and smoker.
These categorical variables are ideal candidates for facets, because they define natural groups you might want to compare visually.

See also  Changing Seaborn Lineplot Color

Creating Your First FacetGrid

To create a simple grid, start by building the FacetGrid object and then “map” a plotting function onto it.
The mapping step is the key idea: you describe one basic chart and Seaborn repeats it for every subset defined by the facet variables.
This keeps the code short even when you are producing dozens of plots.


g = sns.FacetGrid(
    data=tips,
    col="time",
    row="smoker",
    margin_titles=True
)

g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")

plt.tight_layout()
plt.show()
    

This code builds a grid with columns based on the time of day and rows based on whether the customer was a smoker.
Each small panel shows a scatter plot of total_bill against tip, so you can scan the grid and check whether the relationship changes across groups.
The same axis limits across the grid make comparisons quick and intuitive.

Adding Color And Customizing Aesthetics

FacetGrid also supports a hue parameter that adds another layer of grouping through color.
You can use hue to distinguish categories inside each panel while keeping the facets themselves for the main split.
With a careful choice of palette and markers, the result remains readable even when you introduce several groups.

See also  How to Make a Kdeplot in Seaborn


g = sns.FacetGrid(
    data=tips,
    col="day",
    hue="sex",
    col_wrap=2,
    height=3,
    palette="Set2"
)

g.map_dataframe(
    sns.scatterplot,
    x="total_bill",
    y="tip",
    alpha=0.8
)

g.add_legend(title="Customer sex")

g.set_axis_labels("Total bill (USD)", "Tip (USD)")
g.set_titles(col_template="{col_name}")

sns.despine(trim=True)
plt.tight_layout()
plt.show()
    

By wrapping the grid and controlling the height, you keep the layout compact while still clear.
The legend explains the meaning of the colors and the axis labels make the chart self‑contained, which is important when you export the figure into a report or dashboard.
Choosing a readable palette such as “Set2” or “pastel” improves accessibility for readers.

Using Different Plot Types On FacetGrid

FacetGrid is not limited to scatter plots.
You can map histograms, kernel density plots, bar charts or any other Seaborn function that accepts a data and keyword arguments style interface.
For distribution analysis, a common combination is to facet by category and then map a histogram or density curve to examine how each group is distributed.


g = sns.FacetGrid(
    data=tips,
    col="day",
    col_wrap=2,
    height=3.2
)

g.map_dataframe(
    sns.histplot,
    x="total_bill",
    kde=True,
    bins=20,
    color="#4c72b0"
)

g.set_axis_labels("Total bill", "Count")
g.set_titles("Day: {col_name}")

plt.tight_layout()
plt.show()
    

This grid reveals whether the spending pattern differs between days of the week.
When you see one panel with a visibly different shape or center than the others, you know that the category has a unique behavior worth investigating.
The uniform binning and shared axes keep the comparison fair.

See also  How to Create a Boxplot in Seaborn

Practical Tips And When To Use FacetGrid

FacetGrid works best when you have one or two categorical variables with a reasonable number of levels.
If a facet variable has ten or more categories, the grid becomes cluttered and hard to read, so consider grouping levels or focusing on the most important values.
You also need enough data in each subset; otherwise a panel may show just a handful of points and invite over‑interpretation.

In practice, FacetGrid shines in exploratory data analysis and in narrative reports where you want to show how a relationship shifts across groups.
It turns one pattern into a series of related views and helps readers follow the story without guessing which filter was active in each chart.
Once you are comfortable with the basics, you can combine FacetGrid with custom functions to build repeatable visualization recipes for your projects.