When plotting multiple lines or data categories, a legend is essential for the reader to identify which color corresponds to which series.
The color-coded key in the corner of a geopolitical map.
Every drawing method (`plot`, `scatter`, `bar`) accepts a `label='...'` argument that registers the series into the active legend handler.
plt.plot(x, y, label='Revenue')Options include 'best' (auto avoid data), 'upper right', 'upper left', 'lower right', 'lower left', 'center'.
plt.legend(loc='best', ncol=2)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
Plot `x=[1, 2, 3]`, `y1=[1, 2, 3]` with label 'Alpha' and `y2=[3, 2, 1]` with label 'Beta', then call `plt.legend()`.
✓ plt.legend✓ labelTest your understanding to unlock the lesson completion badge