From the documentation:
The default transform specifies that text is in data coords, alternatively, you can specify text in axis coords (0,0 is lower-left and 1,1 is upper-right). The example below places text in the center of the axes:
>>> text(0.5, 0.5, 'matplotlib', horizontalalignment='center', ... verticalalignment='center', transform=ax.transAxes)
Can I instead use both data and axis coords? For x and y respectively.
Example code:
import random
import matplotlib.pyplot as plt
values = [random.randint(2,30) for _ in range(15)]
plt.violinplot(values, positions=[1])
# This might place the text outside the figure
plt.gca().text(1, 30, "Text")
# I would like to use axis coords for y instead of data coords. Example call
# would be something like this:
# text_mixed_coords(xdata=1, yaxis=0.9, "Text")
plt.savefig("plot.png")
See also: Putting text in top left corner of matplotlib plot