Skip to content

Plotly Subplots and Facets

  1. Facets (Plotly Express): easiest for grid layouts — one line of code repeats the same chart across a category, split into a grid of small panels (“small multiples”).
  2. Subplots (plotly.subplots): full control — you place arbitrary, even different, chart types into any grid cell yourself.

Facets are for “show me this one chart, once per group.” Subplots are for “let me hand-place several different charts into one figure” (this is exactly what the dashboard page does).

Facet example
import plotly.express as px
 
df = px.data.tips()
 
fig = px.scatter(
    df,
    x="total_bill",
    y="tip",
    color="sex",
    facet_col="day",
    title="Tips by day (facets)",
)
fig.show()

facet_col="day" splits the data by the day column and draws one scatter panel per unique day, all sharing the same axis scale — so panels are directly comparable side by side.

sketch Small multiples: same chart, repeated per group p5.js
Faceting draws one identical mini-chart per category, all on the same scale, side by side.
Subplots
import plotly.graph_objects as go
from plotly.subplots import make_subplots
 
fig = make_subplots(rows=1, cols=2, subplot_titles=["A", "B"])
 
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 4, 9], mode="lines", name="line"), row=1, col=1)
fig.add_trace(go.Bar(x=["x", "y", "z"], y=[5, 2, 6], name="bar"), row=1, col=2)
 
fig.update_layout(title_text="Two plots in one figure")
fig.show()

Unlike facets, the two panels here don’t have to share a scale, an x-axis meaning, or even a chart type — make_subplots just gives you a grid of independent plotting areas.

  • Use facets when you’re comparing the same chart across categories on a shared scale.
  • Use subplots when mixing chart types, or when panels genuinely measure different things.
  • Too many facet panels (more than ~6-8) get cramped — consider filtering to the most important categories first.
diagram Choosing facets vs subplots mermaid
Facets repeat one chart per category on a shared scale; subplots hand-place arbitrary charts into a grid.

Continue to: Animations in Plotly to show change over time or category using frames.

Exercise 3 – Mix Chart Types in One Figure

Section titled “Exercise 3 – Mix Chart Types in One Figure”

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading