Faceting plots in Seaborn works slightly different than it does in ggplot. First, you have to instantiate a grid, then you map plots to this grid. In this way, it works kinda like Makie.jl does.
For example, here’s how to make a faceted histogram showing the height of different species of palm trees, by their palm_tribe
type. The data comes from TidyTuesday
Setup
import polars as pl
import seaborn as sns
import matplotlib.pyplot as plt
# read in data
palmtrees = pl.read_csv(
"https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-03-18/palmtrees.csv",
encoding="latin1",
null_values="NA",
)
# get the 5 palm_tribes with the most species
n_by_tribe = palmtrees.group_by("palm_tribe").len(name="n").sort("n", descending=True)
top_5_tribes = n_by_tribe.head(5)["palm_tribe"]
top5_df = palmtrees.filter(pl.col("palm_tribe").is_in(top_5_tribes)).drop_nulls("max_stem_height_m")
Create Plot
# create the grid
g = sns.FacetGrid(
top5_df.to_pandas(), col="palm_tribe", col_wrap=2, sharex=True, sharey=False
)
# map plots to grid
g.map(sns.histplot, "max_stem_height_m", bins=20)
# show the plot
plt.show()