FacetGrid is the object under relplot and catplot. You can build one yourself and map a plotting function onto each subset. sns.displot is the figure-level histogram/KDE grid.
Goal
Facet a histogram by city with FacetGrid, then with displot.
Map histplot
rng = np.random.default_rng(0)
df = pd.DataFrame(
{
"city": rng.choice(["Nairobi", "Mombasa", "Kisumu"], size=90),
"units": rng.integers(1, 20, size=90),
}
)
g = sns.FacetGrid(df, col="city")
g.map_dataframe(sns.histplot, x="units", bins=8)
plt.show()map_dataframe passes the subset as data= so seaborn functions work.
Hue on the grid
rng = np.random.default_rng(0)
df = pd.DataFrame(
{
"city": rng.choice(["Nairobi", "Mombasa"], size=80),
"product": rng.choice(["A", "B"], size=80),
"units": rng.integers(1, 20, size=80),
}
)
g = sns.FacetGrid(df, col="city", hue="product")
g.map_dataframe(sns.kdeplot, x="units", fill=True, alpha=0.4)
g.add_legend()
plt.show()displot
rng = np.random.default_rng(1)
df = pd.DataFrame(
{
"city": rng.choice(["Nairobi", "Mombasa", "Kisumu"], size=90),
"units": rng.normal(10, 3, size=90),
}
)
sns.displot(data=df, x="units", col="city", kde=True)
plt.show()displot is the distribution counterpart of relplot. Prefer it over a raw FacetGrid unless you need a custom mapped function.
Tip
g.set_axis_labels("units", "count") and g.set_titles("{col_name}") tidy FacetGrid labels after map_dataframe.