Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Facet Grid — Small Multiples for Any Chart

Signature

sp.facet(family, *, variant=None, facet_by, title="", cols=3, cell_width=320, cell_height=280, **kwargs) -> Chart

Aliases: sp.facet, sp.facet_grid, sp.facetgrid, sp.small_multiples, sp.build_facet

Description

sp.facet() is not a chart family of its own — it is the framework's generic small-multiples mechanism, the SeraPlot equivalent of seaborn's FacetGrid. It takes the name of any existing 2D chart family (family=), splits every data array in the call by a facet_by group key, and calls that family's own builder once per group, laying the results out in a grid. Every current and future chart family gets faceting for free — there is no per-chart code, no separate variant enum, and no duplicated geometry: services/plot/statistical/facet/mod.rs dispatches straight to the target family's real build_* function (histogram::build_histogram, line::build_line, joint::build_joint, …), so any **kwargs valid for that family (colorscale=, bins=, variant=, …) is simply forwarded through unfiltered.

Only arguments whose array length matches facet_by get split; everything else (scalars like bins=, variant=, colorscale=) is copied to every cell unchanged. cols= sets the grid's column count, cell_width= / cell_height= size each panel.

Currently wired families: area, bar, boxplot, bubble, bullet, candlestick, dumbbell, eventplot, funnel, gantt, gauge, heatmap, hexbin, histogram, icicle, joint, kde, line, lollipop, parallel, pie, radar, ridgeline, scatter, slope, splom, stackplot, sunburst, treemap, violin, waterfall, wordcloud — see facet::dispatch() for the exact match table.

Data

Any array field accepted by the target family= (values, labels, x, y, …), plus facet_by (list[str]) — the group label for each row, same length as the arrays being split.

Recipes

Not every case needs its own SeraPlot demo — some seaborn gallery examples are already one call away from an existing chart page:

  • Multiple ECDFs (overlaid, not facetted) — histogram(variant="cumulative", color_groups=...) or kde(variant="cumulative", categories=...): seaborn overlays several ECDF lines in one panel via category grouping, which is the same color_groups= / categories= convention already used for stacking and multi-series density.
  • Pair grid (KDE diagonal, paired point plots, dot-plot matrix) — splom(variant="density") or splom(variant="basic"): SPLOM is SeraPlot's scatterplot-matrix family and already covers the pairwise-comparison layout these seaborn examples show.
  • Radial facetsfacet(family="bar", facet_by=...): SeraPlot doesn't have a native polar/rose histogram variant yet, so this reproduces the faceting technique with a regular bar chart per facet rather than a pixel-perfect polar match.
  • Facetted time series — same mechanism as the Faceted Lineplot recipe below; swap in a time-ordered labels= array.

One histogram panel per facet_by group — matches seaborn's faceted_histogram example.

Call facet(family="histogram", values=[...], facet_by=[...], cols=2)
Preview

One line panel per group — matches seaborn's faceted_lineplot / timeseries_facets examples (use a time-ordered labels= for the latter).

Call facet(family="line", labels=[...], values=[...], facet_by=[...], cols=3)
Preview

Faceting scales to any number of groups — matches seaborn's many_facets example.

Call facet(family="bar", labels=[...], values=[...], facet_by=[...], cols=3)
Preview

One KDE curve per condition — matches seaborn's multiple_conditional_kde example.

Call facet(family="kde", values=[...], facet_by=[...], cols=3)
Preview

Facets a bivariate joint(variant="histogram2d") panel by a third variable — matches seaborn's three_variable_histogram example, combining the facet mechanism with the [`joint`](joint.md) family's `histogram2d` alias.

Call facet(family="joint", variant="histogram2d", x=[...], y=[...], facet_by=[...], cols=2)
Preview