To put several Plotly charts in one figure, create the grid with make_subplots(rows=..., cols=...) from plotly.subplots, then add each trace to a cell with fig.add_trace(trace, row=..., col=...). subplot_titles labels each panel, shared_xaxes=True links the x-axes, and specs=[[{"secondary_y": True}]] gives a subplot a second y-axis. Plotly Express functions can't target a cell directly, but you can copy their traces in, or use facet_col for small multiples.
Quick Example
import plotly.graph_objects as go
from plotly.subplots import make_subplots
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
rain_mm = [140, 95, 95, 70, 50, 40, 15, 25, 40, 90, 150, 150]
high_c = [8, 10, 12, 15, 19, 22, 26, 26, 23, 16, 11, 8]
fig = make_subplots(rows=1, cols=2,
subplot_titles=("Monthly rainfall (mm)", "Average high (°C)"))
fig.add_trace(go.Bar(x=months, y=rain_mm, name="Rainfall", marker_color="#2563eb"),
row=1, col=1)
fig.add_trace(go.Scatter(x=months, y=high_c, name="High temp", mode="lines+markers",
line=dict(color="#dc2626", width=3)),
row=1, col=2)
fig.update_layout(title_text="Seattle climate by month", showlegend=False)
fig.show()
The bar chart on the left shows rainfall dropping from 140 mm in January to 15 mm in July. The line on the right shows the average high peaking at 26 °C in July and August. Each panel has its own x- and y-axis. The code targets Plotly 6.
How make_subplots Works
make_subplots returns an ordinary go.Figure with the layout pre-split into a grid of axes. rows and cols set the grid, and row/col in add_trace are 1-indexed, so the top-left cell is row=1, col=1.
Behind the scenes each cell gets its own axis pair, named xaxis/yaxis, xaxis2/yaxis2, and so on, numbered left to right and then top to bottom. You rarely need those names because the update methods also accept row and col:
fig.update_yaxes(title_text="mm", row=1, col=1)
fig.update_yaxes(title_text="°C", row=1, col=2)
fig.update_xaxes(tickangle=-45) # no row/col: applies to every subplot
fig.print_grid() prints the grid layout and the axis names for each cell, which helps when a layout gets complicated.
Share the X-Axis and Set Row Heights
For charts that share a time axis, like a price and its trading volume, stack them in one column with shared_xaxes=True. Zooming or panning one panel moves the other, and only the bottom panel shows x tick labels. row_heights sets the relative height of each row and vertical_spacing the gap between them, as a fraction of the figure height.
import numpy as np
rng = np.random.default_rng(8)
days = np.arange("2026-08-03", "2026-10-31", dtype="datetime64[D]")
days = days[np.is_busday(days)]
price = (120 * np.exp(np.cumsum(rng.normal(0.002, 0.015, len(days))))).round(2)
volume = (rng.lognormal(14.5, 0.35, len(days)) / 1e6).round(2)
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.04,
row_heights=[0.7, 0.3])
fig.add_trace(go.Scatter(x=days, y=price, name="Close",
line=dict(color="#0f766e", width=2)),
row=1, col=1)
fig.add_trace(go.Bar(x=days, y=volume, name="Volume", marker_color="#94a3b8"),
row=2, col=1)
fig.update_yaxes(title_text="Close ($)", row=1, col=1)
fig.update_yaxes(title_text="Volume (M)", row=2, col=1)
fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])]) # hide weekends
fig.update_layout(title_text="Daily close and volume", showlegend=False,
hovermode="x unified")
fig.show()
Drag across a region of either panel to zoom, and both panels follow. hovermode="x unified" shows the close and the volume for the hovered day in one tooltip. rangebreaks removes the weekend gaps from the date axis.
shared_yaxes=Truedoes the same for panels side by side in a row.column_widths=[0.6, 0.4]andhorizontal_spacingare the column equivalents ofrow_heightsandvertical_spacing.- To link axes that aren't in the same row or column, use
fig.update_xaxes(matches="x").
Add a Secondary Y-Axis
Two measures with different units on the same x-axis need a second y-axis. Turn it on per cell with specs, then pass secondary_y=True to add_trace and update_yaxes:
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(go.Bar(x=months, y=rain_mm, name="Rainfall (mm)", marker_color="#93c5fd"),
secondary_y=False)
fig.add_trace(go.Scatter(x=months, y=high_c, name="Average high (°C)",
mode="lines+markers", line=dict(color="#dc2626", width=3)),
secondary_y=True)
fig.update_yaxes(title_text="Rainfall (mm)", secondary_y=False)
fig.update_yaxes(title_text="Average high (°C)", secondary_y=True, showgrid=False)
fig.update_layout(title_text="Seattle climate: rainfall and temperature",
legend=dict(orientation="h", y=1.02, yanchor="bottom", x=1, xanchor="right"))
fig.show()

Rainfall bars use the left axis in millimeters and the temperature line uses the right axis in °C. That makes the inverse pattern easy to see: the wettest months are the coldest. showgrid=False on the secondary axis avoids two sets of gridlines that don't line up.
specs is a list of rows, each a list of dicts, one per column. In a grid it looks like specs=[[{"secondary_y": True}, {"secondary_y": True}]], and then add_trace(..., row=1, col=2, secondary_y=True). Dual axes can mislead when the two scales are chosen to suggest a relationship. See the dual y-axes post for when they're worth it.
Mix Chart Types and Span Cells with specs
Cells are "xy" (Cartesian) by default. Pies, sunbursts, and other charts without x/y axes need "type": "domain", and other trace types have their own subplot type: "polar", "scene" (3D), "ternary", "map". specs also sets colspan and rowspan. Put None in a cell that another cell spans over.
quarters = ["Q1", "Q2", "Q3", "Q4"]
downloads = {"iOS": [120, 150, 170, 210], "Android": [180, 190, 230, 260], "Web": [60, 75, 70, 90]}
colors = {"iOS": "#7c3aed", "Android": "#16a34a", "Web": "#f59e0b"}
ratings = {"iOS": 4.6, "Android": 4.3, "Web": 4.1}
fig = make_subplots(
rows=2, cols=2,
specs=[[{"type": "xy", "colspan": 2}, None],
[{"type": "domain"}, {"type": "xy"}]],
subplot_titles=("Downloads by quarter (thousands)", "Share of downloads", "Average rating"),
vertical_spacing=0.12,
)
for platform, values in downloads.items():
fig.add_trace(go.Scatter(x=quarters, y=values, name=platform, mode="lines+markers",
line=dict(color=colors[platform], width=3)),
row=1, col=1)
fig.add_trace(go.Pie(labels=list(downloads), values=[sum(v) for v in downloads.values()],
marker_colors=list(colors.values()), hole=0.45, sort=False,
showlegend=False),
row=2, col=1)
fig.add_trace(go.Bar(x=list(ratings), y=list(ratings.values()),
marker_color=list(colors.values()), showlegend=False,
text=list(ratings.values()), textposition="outside"),
row=2, col=2)
fig.update_yaxes(range=[0, 5], row=2, col=2)
fig.update_layout(title_text="App dashboard", height=640)
fig.show()

The line chart spans both top cells, and the bottom row has a donut chart next to a bar chart. Android has the most downloads (47.6%) and iOS the highest rating (4.6). If you forget "type": "domain" for the pie, Plotly raises ValueError: Trace type 'pie' is not compatible with subplot type 'xy'.
Use Plotly Express Charts in Subplots
Plotly Express returns whole figures, so there's no row=/col= argument. When you want the same chart split by a category, use the built-in faceting instead of make_subplots:
import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", color="sex", facet_col="day",
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"]})
When the panels are different charts, build each one with Express and copy its traces into the grid:
bar = px.bar(x=months, y=rain_mm)
line = px.line(x=months, y=high_c, markers=True)
fig = make_subplots(rows=1, cols=2)
for trace in bar.data:
fig.add_trace(trace, row=1, col=1)
for trace in line.data:
fig.add_trace(trace, row=1, col=2)
Only the traces are copied, so the Express figure's axis titles and layout settings are lost. Set those on the new figure with update_xaxes/update_yaxes.
Style Subplot Titles, Spacing, and Legends
- Subplot title font: subplot titles are annotations, so use
fig.update_annotations(font_size=13). - Spacing:
horizontal_spacingdefaults to0.2 / colsandvertical_spacingto0.3 / rows, as fractions of the figure. Shrink them for dense grids, and raisevertical_spacingif tick labels collide with the next panel's title. - Figure size: set
fig.update_layout(height=..., width=...)for the whole figure. Individual subplots don't have their own size, butrow_heights/column_widthscontrol the proportions. - Duplicate legend entries: if the same series appears in several panels, set
showlegend=Falseon the repeats, and give each pair a sharedlegendgroupso clicking the legend toggles both. - Axis titles shared by a whole row or column:
make_subplots(..., x_title="Month", y_title="Value")adds one centered title instead of one per panel.
For keeping square panels square, see How to Set Fixed Aspect Ratios for Subplots in Plotly.
make_subplots vs Faceting vs Separate Figures
| Approach | Best for | Limits |
|---|---|---|
make_subplots |
Different chart types or measures in one figure, shared or secondary axes | More code; Express figures must be copied in trace by trace |
px.*(facet_col=..., facet_row=...) |
The same chart repeated for each category | Every panel must be the same chart type |
| Separate figures (or a Dash layout) | Independent charts on a page or dashboard | No linked zoom or shared hover between charts |

