It is probably best to determine the position in the coordinates of the figures instead of the coordinates of the data, since you probably do not want the text to change its position when the data changes.
Using the coordinates of the figure can be done either by setting the transformation of the figure ( fig.transFigure
)
plt.text(0.02, 0.5, textstr, fontsize=14, transform=plt.gcf().transFigure)
or using the text
method of the shape, not the axis axis.
plt.gcf().text(0.02, 0.5, textstr, fontsize=14)
In both cases, the coordinates for placing the text are in the coordinates of the figures, where (0,0)
is in the lower left and (1,1)
in the upper right corner of the figure.
In the end, you might still want to provide extra space for text that fits near the axes using plt.subplots_adjust(left=0.3)
or so.
source share