Matplotlib & Visualisation · Lesson 141

Titles Labels and Legends

Titles Labels and Legends is part of statistical graphics.

ConceptWorked examplePracticeKnowledge check
Textbook walkthrough

What Titles Labels and Legends actually means

Titles Labels and Legends is part of statistical graphics. A chart is not decoration: it maps variables to visual position, length, shape or other encodings so that a particular comparison becomes easier to see.

Titles Labels and Legends matters because a visualisation is a mapping from data to visual encodings. A technically valid plot can still mislead if the chart type, scale, labels or grouping do not match the analytical question.

Deeper walkthrough

Read Titles Labels and Legends as a mechanism, not a recipe

Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Decide whether a plot matches the analytical question and variable types. Stage 2: Create the figure/axes and plot the data with a truthful scale. Stage 3: Label axes with variable names and units; use a title that states the question or finding. Final checkpoint: Check accessibility, clutter, aspect ratio and whether the chart could exaggerate or hide a pattern.

Mechanism

Follow the transformation

Decide whether a plot matches the analytical question and variable types.

Create the figure/axes and plot the data with a truthful scale.

Label axes with variable names and units; use a title that states the question or finding.

Evidence

Know what would convince you

  • Reconcile plotted marks/bars/bins/lines with a few source values and the intended aggregation.
  • Check axis limits, units, category order and any binning/smoothing choices explicitly.
Useful distinctionBar chart: Compare magnitudes across categories.
How it works

Trace the mechanism step by step

  1. Decide whether a plot matches the analytical question and variable types.
  2. Create the figure/axes and plot the data with a truthful scale.
  3. Label axes with variable names and units; use a title that states the question or finding.
  4. Add annotations/reference lines only when they help interpretation.
  5. Check accessibility, clutter, aspect ratio and whether the chart could exaggerate or hide a pattern.
Worked demonstration

Make the concept concrete

Demonstration

Python / Matplotlib example

# Step 1 — Import the module so its functions/classes are available to the rest of this example.
import matplotlib.pyplot as plt
# Step 2 — Compute the right-hand expression and store its result in `months` for the next step.
months = ["Jan", "Feb", "Mar", "Apr"]
# Step 3 — Compute the right-hand expression and store its result in `sales` for the next step.
sales = [82, 96, 91, 118]
# Step 4 — Encode the selected variables into a visual layer that can be inspected for pattern and anomalies.
fig, ax = plt.subplots()
# Step 5 — Encode the selected variables into a visual layer that can be inspected for pattern and anomalies.
ax.plot(months, sales, marker="o")
# Step 6 — Execute this statement and inspect how it changes the current value, object or program state.
ax.set(title="Monthly sales", xlabel="Month", ylabel="Sales ($000)")
# Step 7 — Execute this statement and inspect how it changes the current value, object or program state.
ax.grid(axis="y", alpha=.25)
# Step 8 — Render the completed visual so the encoded pattern can be inspected.
plt.show()
Expected / illustrative result
A four-point line chart showing sales rising overall from Jan to Apr, with a small dip in Mar.
Interpret the result.

For Titles Labels and Legends, identify which source values create each important mark/position, then check whether scale, ordering, aggregation or binning could change the visual conclusion.

Distinctions & related ideas

Know what this is — and what it is not

Bar chartCompare magnitudes across categories.
HistogramShow the distribution of one numeric variable across bins.
Line chartShow ordered change, usually over time.
Scatter plotShow the relationship between two numeric variables.
Box plotCompact view of median, quartiles and potential outliers across groups.
Use deliberately

When it is appropriate

Use Titles Labels and Legends when its visual encoding matches the variable types and the comparison/pattern the reader needs to see.

Boundary conditions

When to stop or reconsider

Choose a different chart or representation when this encoding hides distribution, order, uncertainty or observation-level structure, or when overplotting/scale choices would make the display misleading.

Common mistakes

Failure modes to recognise

  • Using a chart type whose marks/axes do not match the data types or analytical question.
  • Allowing scale, binning, category order or aggregation to create a visual impression the raw values do not support.
  • Adding colour, labels or decoration without a clear encoding purpose or accessible alternative.
Verification

How to check the result

  • Reconcile plotted marks/bars/bins/lines with a few source values and the intended aggregation.
  • Check axis limits, units, category order and any binning/smoothing choices explicitly.
  • Change one data value or filtering rule and predict which visual element should move before regenerating the figure.
Hands-on practice

Demonstrate understanding

Try this:

Build a tiny, inspectable example of Titles Labels and Legends. First decide whether a plot matches the analytical question and variable types. Then create the figure/axes and plot the data with a truthful scale. Write the expected result before running it, and explain one condition that would make the result misleading or invalid.

Use a handful of values and label the axes/units. Point to each visual mark and identify the source value or aggregation that created it.
Knowledge check

Check reasoning, not memorisation

Before trusting a result from Titles Labels and Legends, which check provides the strongest evidence that you understand and applied it correctly?

Quick reference

Keep the important distinctions visible

Step 1Decide whether a plot matches the analytical question and variable types.
Step 2Create the figure/axes and plot the data with a truthful scale.
Step 3Label axes with variable names and units; use a title that states the question or finding.
Step 4Add annotations/reference lines only when they help interpretation.
Lesson summary

What to remember

  • Titles Labels and Legends is part of statistical graphics. A chart is not decoration: it maps variables to visual position, length, shape or other encodings so that a particular comparison becomes easier to see.
  • Decide whether a plot matches the analytical question and variable types.
  • Using a chart type whose marks/axes do not match the data types or analytical question.
  • Reconcile plotted marks/bars/bins/lines with a few source values and the intended aggregation.