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:
fig, axes = plt.subplots(2, 1, sharex=True) # same x-axis, alignedfig, 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):
ax1.plot(months, temp, color="red")ax1.set_ylabel("Temp (°C)", color="red")ax2 = ax1.twinx() # share x, new y on the rightax2.plot(months, rain, color="blue")ax2.set_ylabel("Rain (mm)", color="blue")
Key takeaways
- 01sharex/sharey put subplots on the same scale and link their zoom.
- 02Sharing enables fair visual comparison across panels.
- 03ax.twinx() adds a second y-scale (right side) for different-unit series.
- 04Use twin axes carefully — mismatched scales can mislead; colour-code each line to its axis.
