Python Central HubSign in

Data Analytics with Python / Phase 5: Data Visualization with Matplotlib

Axis Labels and Titles

Make plots understandable - add titles, labels, units, and consistent formatting.

Always label your charts

Without labels, your chart is incomplete. McKinney's rule of thumb: set_xlabel names the x-axis, set_title names the whole subplot, and both can be set together with one call to ax.set(title=..., xlabel=..., ylabel=...) — handy once you're labelling many subplots at once.

diagram Labelling a plot mermaid
Every plot needs a title (the question it answers) plus labelled, unit-carrying axes.
Python
import matplotlib.pyplot as plt
 
x = [1, 2, 3, 4]
y = [100, 120, 90, 150]
 
plt.figure(figsize=(7, 4))
plt.plot(x, y, marker="o")
plt.title("Daily orders")
plt.xlabel("Day")
plt.ylabel("Orders")
plt.tight_layout()
plt.show()

Include units

Examples:

  • Revenue (₹)
  • Duration (seconds)
  • Conversion rate (%)

Tip

A good title explains the question, not just the chart type.

Bad: "Line chart"

Better: "Daily orders increased after campaign launch"

Check your understanding

quizCheck yourself
  1. Which single call sets the title and both axis labels on an Axes?

    Show answer

    A — ax.set(title=..., xlabel=..., ylabel=...) — ax.set combines several setters, which is handy when labelling many subplots.

  2. Which pyplot calls label the x-axis and y-axis?

    Show answer

    A — plt.xlabel and plt.ylabel — plt.xlabel("Day") and plt.ylabel("Orders") label the axes, while plt.title names the chart.

  3. Which title does the lesson prefer?

    Show answer

    A — Daily orders increased after campaign launch — A good title explains the question or finding, not just the chart type.

  4. Why include units in axis labels?

    Show answer

    A — So readers know what Revenue (rupees), Duration (seconds) or Rate (%) measure — Units make a number interpretable. Without labels the chart is incomplete.

Next

Continue to Legends and Colors to distinguish multiple series clearly.

🧪 Try It Yourself

Exercise 1 – Title and axis labels together

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Custom tick labels

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Rotate long labels

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did