Skip to main content
Albero Academy

Shared & Twin Axes

Link axes across subplots, and plot two scales on one chart.

Figures & Layout8 min

Two related techniques: sharing axes so subplots zoom together, and twin axes so two different scales share one plot.

Sharing axes

Sharing keeps subplots on the same scale for fair comparison, and links their zoom/pan:

sharex / sharey
fig, axes = plt.subplots(2, 1, sharex=True) # same x-axis, aligned
fig, axes = plt.subplots(1, 3, sharey=True) # same y-scale for comparison

Twin axes

A twin axis puts a second y-scale on the right — for two series with different units (temperature and rainfall):

two y-scales
ax1.plot(months, temp, color="red")
ax1.set_ylabel("Temp (°C)", color="red")
ax2 = ax1.twinx() # share x, new y on the right
ax2.plot(months, rain, color="blue")
ax2.set_ylabel("Rain (mm)", color="blue")

Key takeaways

  1. 01sharex/sharey put subplots on the same scale and link their zoom.
  2. 02Sharing enables fair visual comparison across panels.
  3. 03ax.twinx() adds a second y-scale (right side) for different-unit series.
  4. 04Use twin axes carefully — mismatched scales can mislead; colour-code each line to its axis.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.