Adding arbitrary text

This uses the Axes.text() function. Note that in the script below, writing x=0.5, y=0.5 refers to so-called data coordinates, i.e. 0.5 ppm in both dimensions. This is most straightforward for labelling 2D data.

If you want axes coordinates, i.e. using x=0.5, y=0.5 to refer to the middle of the spectrum, then you need to pass an extra argument transform=ax.transAxes to text(), where ax is the Axes instance you are plotting on.

Coordinate transforms are covered very thoroughly in the Matplotlib transforms tutorial.

Other keyword arguments (to control e.g. colour, font weight, or alignment) can be found in the Matplotlib documentation for text().

import penguins as pg

data_2d = pg.read(".", 2, 1)
data_2d.stage(levels=2e5)
fig, ax = pg.mkplot()

ax.text(x=0.5, y=0.5, s="A peak")

ax.text(x=0.5, y=0.5, s="Middle", transform=ax.transAxes)

pg.show()
../../_images/add_text.svg