annotate() (Matplotlib)
ax.annotate() places text on a plot at a specific data point, optionally with an arrow pointing to it. Use it to call out peaks, label specific markers, or add explanatory notes.
Matplotlib
The core idea is to anchor text to a coordinate: ax.annotate('peak', xy=(3, 9)) drops the label at data point (3, 9). Add xytext to position the text away from the point and arrowprops to draw a connecting arrow, which is how you point at a feature without covering it.
Coordinates can be specified in several systems via xycoords — 'data' (default) uses your axis values, while 'axes fraction' lets you place text relative to the panel (e.g. (0.5, 0.95) for top-center) regardless of the data range. That makes annotate handy for both pointing at data and stamping figure-level notes.
For plain text with no arrow at an arbitrary spot, ax.text(x, y, s) is the simpler sibling; reach for annotate when you want the arrow or the flexible coordinate systems.
Syntax
ax.annotate(text, xy=(x, y), xytext=None, arrowprops=None)Examples
Python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
an = ax.annotate("peak", xy=(1, 1))
print(type(an).__name__)Output:
Annotation