1

I'm annotating my plot with

plt.annotate(
    '30.2',
    xy=(3, y),
    xycoords='data',
    xytext=(3, y - 5),
    textcoords='data',
    arrowprops=dict(facecolor='black', arrowstyle="->")
)

It creates downward arrows as expected but they are not completely vertical.

If I change '30.2' to a en empty string '', they are vertical.

How can I make sure the arrows are vertical no matter how long the text string is?

1
  • can you show us an SSCCE? Commented May 2, 2015 at 10:54

1 Answer 1

2

It's just a matter of text alignment. Try this:

plt.annotate(
    '30.2',
    xy=(3, y),
    xycoords='data',
    xytext=(3, y - 5),
    textcoords='data',
    horizontalalignment='center',
    arrowprops=dict(facecolor='black', arrowstyle="->")
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.