1

I am trying to figure out how matplotlib annotaitons work and I tried the following:

fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, ylim=(1, 9000000))

plt.plot(df['month'], df['France'], label='France')
plt.plot(df['month'], df['Germany'], label='Germany')

ax.annotate('test', xy=(100, 1000), xytext=(3, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

fig.set_size_inches(15, 7)
plt.legend(loc=2)
plt.show()

It is giving me a plot area, but is not showing the lines or the annotations. Any thoughts?

The following works and gives me a graph, but no annotations, obviously:

fig = plt.figure()
ax = fig.add_subplot(autoscale_on=False, ylim=(1, 9000000))

plt.plot(df['month'], df['France'], label='France')
plt.plot(df['month'], df['Germany'], label='Germany')

fig.set_size_inches(15, 7)
plt.legend(loc=2)
plt.show()

1 Answer 1

1

Have you tried adding arrowstyle’='-' (or '->', or '<-' or '<->' depending on what type of line or arrow you want) to your arrowprops dictionary? Note also that the xy coordinates should be in data units, so it may be that (100, 1000) is not within your axes area (I don't know the range of values of your data.)

Sign up to request clarification or add additional context in comments.

4 Comments

My x axis is date time objects and my y axis goes up to 9M
How did you choose 100 and 3 as your x-coordinates for the arrow head and text location?
It was arbitrary, i was just trying to get the text to appear
To check if this is the problem, you could specify both pairs of coordinates in fractional axis coordinates (0-1) for each x and y, and set xycoords='axes fraction' and textcoords='axes fraction' as arguments to annotate

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.