When two correlated metrics share the same X-axis (e.g. date) but operate on completely different scales and units (e.g. Stock Price in $ vs Trading Volume in millions), `ax.twinx()` creates a second Y-axis on the right.
A ruler with inches marked on the left edge and centimeters marked on the right edge.
`ax2 = ax1.twinx()` creates an overlay axes sharing `ax1`'s X-axis coordinates, but possessing an independent right-hand Y-axis.
ax2 = ax1.twinx()
ax2.plot(x, y2, color='green')Avoid the top errors and bad plotting practices that trip up new Python developers
Switch from abstract numbers to relatable Cricket, Cinema & Business charts
Write Matplotlib code to solve the objective and see your live plot render
Create `fig, ax1 = plt.subplots()`, plot `[1, 2, 3]` and `[10, 20, 30]` on `ax1`, then call `ax2 = ax1.twinx()` and plot `[100, 200, 300]` on `ax2`.
✓ twinx✓ set_ylabelTest your understanding to unlock the lesson completion badge