Titles, Labels and Annotations

Python · Data Visualization

Theory

Text turns a picture into an explanation. ax.set_title() states what the chart shows, and ax.set_xlabel() and ax.set_ylabel() name each axis with its unit, for example 'Sales (Rs lakh)'. When an Axes has several series, give each a label= when drawing and call ax.legend(); loc='upper left' or loc='best' controls where the box goes.

Annotations point at a specific spot: ax.annotate('Diwali peak', xy=(x, y), xytext=(x2, y2), arrowprops=dict(arrowstyle='->')) writes text at xytext with an arrow to the data point xy, while ax.text(x, y, 'note') places plain text in data coordinates. ax.axhline(y=target, linestyle='--') draws a reference line such as a target. ax.set_xticks() with rotation fixes crowded tick labels, and ax.set_ylim(0, ...) controls the visible range.

Why we use it

A chart without a title, units or legend forces readers to guess. Clear labels and one or two annotations tell them what to look at, which is what makes a chart useful in a report or presentation.

When to use it

Always add a title and axis labels with units. Add a legend only when there are two or more series, and annotate only the points that matter, such as a peak, a dip or a target line. Too many notes clutter the chart.

How it works

  1. Chart with data drawn
  2. Add a title that says what the chart shows
  3. Label both axes with units
  4. Two or more series? Yes: label= on each, then ax.legend(). No: Skip the legend.
  5. A point the reader must notice? Yes: ax.annotate with an arrow, or a reference line. No: Keep it clean.
  6. Self-explanatory chart

Syntax

ax.set_title('...')  ax.set_xlabel('...')  ax.set_ylabel('...')
ax.plot(x, y, label='...'); ax.legend(loc='best')
ax.annotate('text', xy=(x, y), xytext=(x2, y2), arrowprops=dict(arrowstyle='->'))
ax.axhline(y, linestyle='--')  ax.text(x, y, 'note')

Example

ax.plot(months, sales, label='2024')
ax.set_title('Monthly sales')
ax.set_ylabel('Rs lakh')
ax.annotate('Diwali peak', xy=(9, 310), xytext=(5, 330), arrowprops=dict(arrowstyle='->'))

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic