doc/_docstrings/objects.Plot.facet.ipynb
import seaborn.objects as so
from seaborn import load_dataset
penguins = load_dataset("penguins")
diamonds = load_dataset("diamonds")
Assigning a faceting variable will create multiple subplots and plot subsets of the data on each of them:
p = so.Plot(penguins, "bill_length_mm", "bill_depth_mm").add(so.Dots())
p.facet("species")
Multiple faceting variables can be defined to create a two-dimensional grid:
p.facet("species", "sex")
Facet variables can be provided as references to the global plot data or as vectors:
p.facet(penguins["island"])
With a single faceting variable, arrange the facets or limit to a subset by passing a list of levels to order:
p.facet("species", order=["Gentoo", "Adelie"])
With multiple variables, pass order as a dictionary:
p.facet("species", "sex", order={"col": ["Gentoo", "Adelie"], "row": ["Female", "Male"]})
When the faceting variable has multiple levels, you can wrap it to distribute subplots across both dimensions:
p = so.Plot(diamonds, x="carat", y="price").add(so.Dots())
p.facet("color", wrap=4)
Wrapping works only when there is a single variable, but you can wrap in either direction:
p.facet(row="color", wrap=2)
p.facet("clarity", wrap=3).share(x=False)
p.facet("color").label(title="{} grade".format)