4

I would like to annotate a plot with a vertical arrow, and then center the annotation on the tip of the vertical arrow: enter image description here

Here is the code that I use:

import matplotlib.pyplot as plt
plt.annotate(
# Label and coordinate
'Help here!', xy=(8, 0.4),xytext=(7.05, 0.6) ,
# Custom arrow
arrowprops=dict(arrowstyle='->',lw=1)
)

The xytext coordinates indicate the coordinates at which the text starts. If they are not correctly set, the arros stops being vertical here. For now in order to make the arrow vertical, I need to manually find the correct x coordinate for the variable xytext (for this text it appears to be 7.05). But can I just find a way to indicate what I want as a command?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Fringant
  • 525
  • 1
  • 5
  • 17

1 Answers1

7

ImportanceOfBeingErnest gave me the response in comment. Here is the code associated to his response:

import matplotlib.pyplot as plt
plt.annotate(
# Label and coordinate
'Help here!', xy=(8, 0.4),xytext=(8, 0.6) ,
horizontalalignment="center",
# Custom arrow
arrowprops=dict(arrowstyle='->',lw=1)
)
Fringant
  • 525
  • 1
  • 5
  • 17