Text Annotations
Use Axes.text() (or module-level gleplot.text()) to place text directly in data coordinates,
or in fractions of the axes frame with transform=ax.transAxes.
Basic Usage
import gleplot as glp
fig = glp.figure(figsize=(8, 5))
ax = fig.add_subplot(111)
ax.plot([0, 1, 2], [0.5, 1.3, 0.8])
ax.text(1.0, 1.3, 'Local maximum')
fig.savefig('text_basic.gle')
Alignment Controls
ax.text(2.0, 0.5, 'Left aligned', ha='left', va='center')
ax.text(2.0, 0.2, 'Centered', ha='center', va='center')
ax.text(2.0, -0.1, 'Right aligned', ha='right', va='center')
The accepted ha and va values, and how they map to GLE’s set just, are
in the text() table of the Matplotlib Migration Guide.
Axes Fractions
Pass transform=ax.transAxes to place text relative to the frame instead of
the data, as in matplotlib: (0, 0) is the bottom-left corner and (1, 1)
the top-right, whatever the limits, scale or direction of the axes. A panel
label stays in its corner when the data changes:
ax.text(0.05, 0.95, '(a)', transform=ax.transAxes, va='top')
Figure Text
fig.text() places text in fractions of the whole page, and fig.suptitle()
adds a title above every axes:
fig, axes = glp.subplots(1, 2)
fig.suptitle('Sample A')
fig.text(0.02, 0.98, '(a)', ha='left', va='top')
Rotation
ax.text(1.0, 1.0, 'peak', va='bottom', ha='center', rotation=45)
Font and Color
ax.text(0.5, 1.0, 'Blue note', color='blue', fontsize=12)
Boxed Text
Use the bbox dictionary for callouts that stand out from the data.
ax.text(
3.0,
0.8,
'Fit region',
bbox={'facecolor': 'white'},
)
Which bbox keys are drawn, and which are ignored with a warning, is in the
same text() table.
Arrows
ax.annotate places the text at xytext with an arrow to the point xy,
both in data coordinates:
ax.annotate('peak', xy=(1.0, 1.3), xytext=(1.4, 1.6), arrowprops={'arrowstyle': '->'})
The arrow styles and the arrowprops keys that are honoured are listed in the
Matplotlib Migration Guide.
Using Module-Level Convenience API
import gleplot as glp
glp.figure(figsize=(7, 4))
glp.plot([0, 1, 2], [1, 2, 1])
glp.text(1.0, 2.0, 'Peak')
glp.savefig('text_convenience.gle')
Tips
Place text after plotting so you can choose coordinates with known axis limits.
Use concise labels and avoid overlapping with markers or error bars.
Combine color +
bboxfor high-contrast annotations in dense plots.For reusable patterns, see
examples/advanced/text_annotations.py.