Skip to content
Exercises · Q5

Q.What is the purpose of a legend?

West Bengal WbchseTextbookSubjective· 2mImportance★★★★★est
59% · 26/44 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A legend translates the visual encoding (colors, symbols, line styles) in a chart into plain language, so the reader knows what each graphical element represents.

Why charts need legends

When you plot data, you often encode information through visual properties — a red line for one series, a blue line for another; circles for Category A, squares for Category B; solid lines for actual values, dashed for predicted. The chart itself shows patterns, but without a key the reader has no idea which line is sales and which is profit, or which bar represents which region.

The legend is that key. It maps each visual attribute back to its meaning in the data. Think of it as the Rosetta Stone for your visualization: it decodes the symbols, colors, and styles into the variable names or category labels they stand for.

What a legend contains

A typical legend lists:

  • Color swatches or marker symbols (the visual element used in the plot)
  • Labels (the name of the data series, category, or group that element represents)

For example, in a line chart comparing quarterly revenue across three products, the legend might show:

SymbolLabel
<span style="color:blue;">—</span>Product A
<span style="color:green;">—</span>Product B
<span style="color:red;">—</span>Product C

Without it, three colored lines are just three colored lines.

When legends are essential

You need a legend whenever:

  1. Multiple series appear on the same axes (overlaid lines, grouped bars, stacked areas).
  2. Color or shape encodes a categorical variable (scatter plot where color = species, or pie chart where each slice = department).
  3. The encoding is not self-evident from axis labels alone.

A single-series bar chart with category names on the xx-axis usually does not need a legend — the axis labels already tell the story. But the moment you introduce a second dimension (say, bars grouped by year and region), the legend becomes indispensable.

Tip

In Matplotlib, plt.legend() auto-generates a legend from the label= argument in each plot call. In Pandas, df.plot(legend=True) does the same. Always check that your legend entries match the actual data series. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.