Skip to main content
Albero Academy

Annotations & Text

Point at what matters with text, arrows and reference lines.

Customizing Plots8 min

Annotations direct attention. A well-placed label, arrow or reference line tells the viewer exactly what to notice — turning a chart from "here's data" into "here's the point".

Text & arrows

ax.text and ax.annotate
ax.text(2, 8, "peak", fontsize=12) # plain text at (2, 8)
ax.annotate("record high", # text + an arrow
xy=(x_peak, y_peak), # point to here
xytext=(x_peak + 1, y_peak + 2), # place text here
arrowprops=dict(arrowstyle="->"))

Reference lines

highlight thresholds
ax.axhline(y=target, color="grey", linestyle="--", label="target")
ax.axvline(x=launch_date, color="red")
ax.axhspan(0, 40, alpha=0.1, color="red") # shade a region

Key takeaways

  1. 01ax.text places plain text; ax.annotate adds text with an arrow pointing at a data point.
  2. 02axhline/axvline draw reference lines; axhspan/axvspan shade regions.
  3. 03Annotate the single most important feature — don't clutter.
  4. 04Reference lines are ideal for targets and thresholds.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.