I would like to annotate a plot with a vertical arrow, and then center the annotation on the tip of the vertical arrow:
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?
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)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With