Two ways to create multi-plot layouts
- 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").
- 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).
Facets with Plotly Express
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.
Manual 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.
Tips
- 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.
flowchart TD
A["Need multiple panels"] --> B{"Same chart type,
split by a category?"}
B -- "Yes" --> C["px.scatter(..., facet_col=...)
shared scale, one line of code"]
B -- "No, different chart types
or independent scales" --> D["make_subplots(rows, cols)
+ fig.add_trace(row=, col=)"]
Check your understanding
What does facet_col="day" do in the tips scatter?
Facets repeat the same chart per category on shared axes so panels are directly comparable.
Show answer
B — Draws one scatter panel per unique day, sharing the same axes — Facets repeat the same chart per category on shared axes so panels are directly comparable.
When do you choose make_subplots over facets?
Subplots give full control, so you can mix a go.Scatter and a go.Bar in the same figure.
Show answer
B — When you want to place different chart types in grid cells — Subplots give full control, so you can mix a go.Scatter and a go.Bar in the same figure.
In the manual subplot example, which arguments place the bar in the second panel?
One row and two columns, with the bar placed in column 2 of row 1.
Show answer
A — row=1, col=2 — One row and two columns, with the bar placed in column 2 of row 1.
Why are facets a strong choice for comparing groups?
Shared axes make the differences between small multiples the story.
Show answer
B — Every panel shares the same axes and scale, so panel-to-panel differences stand out — Shared axes make the differences between small multiples the story.
Next
Continue to: Animations in Plotly to show change over time or category using frames.
🧪 Try It Yourself
Exercise 1 – Facet by Category
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Build a Subplot Grid
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Mix Chart Types in One Figure
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.