Facet Grids
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
Facet with displotdisplot
Facet distribution
import seaborn as sns
tips = sns.load_dataset("tips")
sns.displot(data=tips, x="total_bill", col="time", bins=20, kde=True)Facet distribution
import seaborn as sns
tips = sns.load_dataset("tips")
sns.displot(data=tips, x="total_bill", col="time", bins=20, kde=True)Facet with relplotrelplot
Facet relationship
import seaborn as sns
tips = sns.load_dataset("tips")
sns.relplot(data=tips, x="total_bill", y="tip", col="time", hue="sex")Facet relationship
import seaborn as sns
tips = sns.load_dataset("tips")
sns.relplot(data=tips, x="total_bill", y="tip", col="time", hue="sex")Using FacetGridFacetGrid directly
FacetGrid
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()FacetGrid
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()Tips
- Facets can get crowded—keep category counts small.
- Facets are excellent for storytelling and comparisons.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
