Python Central HubSign in

Data Analytics with Python / Phase 7: Interactive Visualization with Plotly

Plotly Subplots and Facets

Create multiple plots in one figure using Plotly Express facets and Plotly subplots.

Two ways to create multi-plot layouts

  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).

Facets with Plotly Express

Python
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.

Manual subplots

Python
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.
diagram Choosing facets vs subplots mermaid
Facets repeat one chart per category on a shared scale; subplots hand-place arbitrary charts into a grid.

Check your understanding

quizCheck yourself
  1. What does facet_col="day" do in the tips scatter?

    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.

  2. When do you choose make_subplots over facets?

    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.

  3. In the manual subplot example, which arguments place the bar in the second panel?

    Show answer

    A — row=1, col=2 — One row and two columns, with the bar placed in column 2 of row 1.

  4. Why are facets a strong choice for comparing groups?

    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

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Build a Subplot Grid

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Mix Chart Types in One Figure

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did