Python Academy · Lesson

Customizing Plots

Add titles, labels, and legends.

Lesson 3 of 413 steps

Customizing Plots is a free Python Academy lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 4 lessons in total.

From Raw to Readable

A bare chart shows data but tells the reader little. Customization adds the context that turns a plot into a clear message: titles, axis labels, legends, ticks, and annotations.

All of these are methods on the axes object.

Titles

Give every axes a title with ax.set_title('Monthly Sales'). A figure-wide title uses fig.suptitle('Report').

The title should state what the chart shows, not just repeat the column name.

raw_label = 'sales_q1'
nice_title = raw_label.replace('_', ' ').title()
print('Title:', nice_title)

Axis Labels

Label both axes with ax.set_xlabel('Month') and ax.set_ylabel('Revenue (USD)'). Always include units when they exist.

Unlabeled axes are the most common reason a chart confuses its audience.

Legends

When an axes has multiple series, a legend identifies them. Pass a label when plotting, then call ax.legend().

The legend reads the labels you attached to each plotted line.

series = [
    {'label': 'Revenue', 'color': 'blue'},
    {'label': 'Costs', 'color': 'red'},
]
for s in series:
    print('legend entry:', s['label'], '(' + s['color'] + ')')

Colors

Set a color with the color argument. You can use names like 'red', hex codes like '#1f77b4', or short codes like 'g'.

Consistent colors across charts help readers track the same series.

Axis Limits

Control the visible range with ax.set_xlim(0, 10) and ax.set_ylim(0, 100). This is useful to zoom in or to force a zero baseline so bar heights are honest.

Here we compute a padded range automatically.

values = [12, 45, 33, 27]
lo, hi = min(values), max(values)
pad = (hi - lo) * 0.1
print('y limits:', lo - pad, 'to', hi + pad)

Ticks and Tick Labels

Ticks are the marks on an axis. Set their positions with ax.set_xticks([0, 1, 2]) and their text with ax.set_xticklabels(['Jan', 'Feb', 'Mar']).

Rotating long labels with rotation=45 prevents overlap.

Gridlines

Add a grid with ax.grid(True) to help readers estimate values. Keep grids light so they do not compete with the data.

You can show only horizontal gridlines with ax.grid(axis='y').

Annotations

Call out a specific point with ax.annotate('Peak', xy=(x, y)). Annotations draw attention to the part of the chart that matters most.

Finding the point to annotate is ordinary Python.

data = [10, 25, 80, 40, 15]
peak_index = data.index(max(data))
print('Annotate peak at x =', peak_index, 'value =', data[peak_index])

Layout Polish

After adding labels, call fig.tight_layout() so nothing is clipped. This automatically adjusts spacing so titles and labels fit within the figure.

It is the final touch before saving or displaying.

Text Styling

Most text methods accept styling arguments: fontsize, fontweight='bold', and color. For example ax.set_title('Sales', fontsize=16, fontweight='bold') emphasizes the title.

Use emphasis sparingly so the data, not the decoration, stays the focus.

Quick Check

Pick the right method for the job.

Recap

You learned the customization toolkit:

  • set_title, set_xlabel, set_ylabel for context
  • legend for naming series, color for consistency
  • set_xlim / set_ylim, ticks, and grid
  • annotate for emphasis and tight_layout for polish

Together they turn raw data into a clear story.

Free to start

Learn Python with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
76
Lessons
320

Frequently Asked Questions

Is the “Customizing Plots” lesson free?

Yes — the full text of “Customizing Plots” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO. The Python Academy course includes 4 lessons in total.

What will I learn in “Customizing Plots”?

Add titles, labels, and legends. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Customizing Plots” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Figures and Axes
  2. Line, Bar and Scatter Plots
  3. Customizing Plots
  4. Subplots and Layouts
← Back to Python Academy