Use sharex and sharey in plt.subplots() to coordinate subplot axes, then use fig.supxlabel() and fig.supylabel() for labels that belong to the whole figure. Choose a sharing mode that matches the comparisons your plots need: shared axes synchronize scale and limits, while independent axes let each panel use its own range.
Share axes when you create the subplot grid
Pass sharex and sharey to plt.subplots(). For a 2-by-2 grid that shares x within each column and y within each row:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
fig, axs = plt.subplots(
2, 2,
sharex="col",
sharey="row",
layout="constrained",
)
for ax in axs.flat:
ax.plot([0, 1, 2], [0, 1, 0])
ax.label_outer()
fig.supxlabel("Time")
fig.supylabel("Measurement")
plt.show()
This combines directional sharing, outer tick-label cleanup, and figure-wide labels. Adapt the sharing mode to the relationships among your data rather than applying one configuration to every grid. The current stable Matplotlib pyplot.subplots reference documents these options.
Choose a sharing mode that fits the comparison
Sharing is a scale and coordination choice, not just a way to reduce duplicate labels. Shared axes coordinate the relevant axis behavior and limits; Matplotlib’s shared-axis example notes that autoscaling considers data across shared Axes. This makes a common range useful when readers need to compare panels directly.
#1 Best Overall
| Setting | What it shares | When it can help |
|---|---|---|
sharex=True or sharex="all" |
The x axis across all subplots | Use when every panel should use a coordinated x axis. |
sharey=True or sharey="all" |
The y axis across all subplots | Use when every panel should use a coordinated y axis. |
sharex="row" or sharey="row" |
The named axis within each row | Use when panels in the same row should be coordinated. |
sharex="col" or sharey="col" |
The named axis within each column | Use when panels in the same column should be coordinated. |
sharex=False or sharex="none"; likewise for sharey |
Nothing; each subplot’s axis remains independent | Use when panels need different ranges or should not be coordinated. |
The row and col modes are supported for either axis dimension. For example, vertical time-series panels often share x, while panels being compared across columns may share y—but the data and intended comparison should determine the choice. The stable API documents "all" as equivalent to True and "none" as equivalent to False.
Understand missing tick labels on shared axes
Matplotlib suppresses some tick labels by default when axes are shared, reducing repetition. With x axes shared in a column, only the bottom subplot’s x tick labels are created by default. With y axes shared in a row, only the first-column subplot’s y tick labels are created by default.
Rank #2
Keep only labels on the grid’s outer edges
Call label_outer() for each Axes to hide interior tick labels and retain those on the outside edges:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
for ax in axs.flat:
ax.label_outer()
This is useful when the grid has several rows or columns and repeated labels would clutter the view.
Rank #3
Restore labels on a specific subplot
If an interior panel needs visible tick labels, enable them selectively with tick_params. For example:
axs[0, 0].tick_params(labelbottom=True)
Choose the relevant Axes and tick-label setting for the panel you want to restore. The shared-axis example documents both the default behavior and label controls.
Rank #4
Add one axis label for the whole figure
Use Figure.supxlabel() and Figure.supylabel(), usually called as fig.supxlabel("Time") and fig.supylabel("Measurement"). These add a shared x- or y-axis label at figure level rather than repeating the same label on every panel. Matplotlib’s figure-label example demonstrates them alongside shared axes.
Keep per-panel labels where panels represent different quantities or need distinct descriptions. A figure-wide label can describe a dimension common to the layout without implying that all panels contain identical data.
Plan sharing before building the figure
Matplotlib’s API states that shared axes cannot be unshared after creation. Set sharex and sharey in plt.subplots() when the grid is made. Custom sharing through Axes.sharex or Axes.sharey is also available, but it does not make sharing reversible.
The examples here follow the current stable Matplotlib documentation, which identified version 3.11.1/3.11.2 on October 4, 2026. Because the stable documentation alias can advance, check the API reference for your installed Matplotlib version if you are maintaining code on an older release.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




