Chapter 1 · Practice 4 of 4
Split crowded charts into small multiples
Why it matters
The Analysis Function notes that more than four lines often makes a line chart too cluttered, and recommends a maximum of four categories in each stacked bar and four bars per cluster. When you have more series than that, split them.
Small multiples repeat the same small chart for each category, with shared axes, so readers compare shapes without decoding colors. All three libraries support them:
- matplotlib:
plt.subplots(nrows, ncols, sharex=True, sharey=True) - Plotly Express: the
facet_colandfacet_rowarguments - Vega-Lite: the
facetencoding or therowandcolumnchannels
Example
import plotly.express as px
fig = px.line(df, x="month", y="signups", facet_col="region", facet_col_wrap=3)
fig.update_yaxes(matches="y") # shared y scale so panels compare fairly
fig.show()