Using Plotly’s make_subplots to Build Multi‑Plot Figures with Shared Axes
Learn how Plotly’s make_subplots function creates a grid of plots with optional shared X or Y axes, reducing boilerplate layout code.
08 Dec 2025, 11:51 UTC

Useful answer
Plotly’s make_subplots function lets you quickly assemble a grid of plots with optional shared X or Y axes, reducing boilerplate layout code.
How it works
The function returns a Figure object that already contains a grid layout defined by rows and cols. When you set shared_xaxes=True or shared_yaxes=True, the corresponding axes of all subplots are linked so that zooming or panning in one subplot updates the others. You then add traces to specific cells using add_trace and supplying the row and col arguments.
Worked example
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Create a 2×2 grid with shared X and Y axes
fig = make_subplots(
rows=2, cols=2,
shared_xaxes=True,
shared_yaxes=True
)
# Add a scatter trace to each subplot
for i in range(1, 5):
fig.add_trace(
go.Scatter(x=[0, 1, 2], y=[i, i*2, i*3], name=f'Trace {i}'),
row=(i-1)//2 + 1,
col=(i-1)%2 + 1
)
fig.show()
The loop calculates the correct row and col indices for each trace, ensuring the four scatter plots fill the grid.
Limits
- Performance can degrade when the number of subplots grows large (roughly >50) because each subplot adds DOM nodes, slowing rendering and interaction.
- Shared‑axis settings must be supplied when the figure is created; they cannot be toggled later without rebuilding the
Figureobject. - When exporting static images, the optional
kaleidoengine is required forfig.write_image(); without it the call will raise an error even thoughfig.show()may still work in a notebook.
Common mistakes
- Omitting
shared_xaxesorshared_yaxeswhen synchronization is desired, resulting in independent axes. - Mis‑calculating the
row andcol indices, which places traces in unintended cells or raises anIndexError. - Attempting to add a trace created with
plotly.expressdirectly to amake_subplotsfigure; such traces must be extracted (e.g.,fig_express.data) before adding.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.