Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Given a DataFrame like:

             LIST_PRICE      SOLD_PRICE
MOYRLD      
1999-03-31   317062.500000   314800
1999-06-30   320900.000000   307100
1999-09-30   400616.666667   366160
1999-12-31   359900.000000   NaN
2000-03-31   359785.714286   330750

Using the code:

import matplotlib.dates as mdates
ax3=df5.plot()
ax3.set_ylim(100000,600000)
ax3.set_title('Heatherwood-Quarterly')

I generate a plot like:

Heatherwood example

I cannot figure out how to get the axis to attach an annotation? This example Annotate Time Series plot in Matplotlib is very close but I don't know how to specify the x and y axis from the DataFrame?

So it should be close to:

ax3.annotate('Test', (mdates.date2num(x[1]), y[1]), xytext=(15, 15), 
            textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))

fig.autofmt_xdate()
plt.show()

But what do I use instead of x[1] and y[1] to get the axis? I tried ['MORLD'][1] and ['SOLD_PRICE'][1] and got index out of range...

share|improve this question
1  
loo at the last link: pandas.pydata.org/pandas-docs/dev/cookbook.html#plotting – Jeff Jul 26 '13 at 21:46
    
Does not seem that it is using a Dataframe with Dataframe indexing? – dartdog Jul 27 '13 at 2:35
    
With pandas 0.11.0, and matplotlib 1.2.1 it seems to function properly if you use ax.annotate('Test', (df5.index[1], df5['SOLD_PRICE'][1]), .... At least if the index of your DataFrame is a DatetimeIndex. – hooy Jul 27 '13 at 11:19
    
@nordev Beautiful!! Please post as the answer so I can mark properly! just could not work out the DF index access syntax! Thank you so much – dartdog Jul 27 '13 at 13:54
up vote 12 down vote accepted

You can access the index values with the index attribute of the DataFrame. So you can simply use

ax3.annotate('Test',
             (df5.index[1], df5['SOLD_PRICE'][1]),
             xytext=(15, 15), 
             textcoords='offset points',
             arrowprops=dict(arrowstyle='-|>'))

This gives (based on your sample data) the below output:

enter image description here

share|improve this answer
1  
Very helpful, thanks! – dartdog Jul 28 '13 at 1:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.