I need to mark certain values in a plot without changing axes limits, e.g., I want a vertical line at x=pi/2
to mark the max(cos(x))
but I don’t want to figure out the appropriate y
limits and I just want my vertical line to go from 33% to 67% of the axes. So, as per vertical & horizontal lines in matplotlib, I am using axvline
.
Now, I want to annotate the vertical line with vertical text next to it (thus annotate
is out).
Thus I need to use text
(see, e.g., Add text next to vertical line).
Alas, text
requires x
and y
in data coordinates. Yes, “the coordinate system can be changed using the transform parameter“, but I need x
in data and y
in axis coordinates!
So, how do I annotate an axvline
with vertical text?