2013-07-26 70 views
8

给出一个DataFrame,如:诠释点Matplotlib情节

   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 

使用代码:

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

我产生这样一个情节:

Heatherwood example

我无法弄清楚如何让轴附加一个nnotation? 这个例子Annotate Time Series plot in Matplotlib非常接近,但我不知道如何从DataFrame指定x轴和y轴?

所以应该接近:

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

fig.autofmt_xdate() 
plt.show() 

但我应该使用什么来代替x[1]y[1]得到轴?我试图['MORLD'][1]['SOLD_PRICE'][1],并得到index out of range ......

+1

厕所在最后一个环节:http://pandas.pydata.org/pandas -docs/dev/cookbook.html#plotting – Jeff

+0

似乎没有在Dataframe索引中使用Dataframe? – dartdog

+0

随着大熊猫0.11.0和matplotlib 1.2.1看来,如果你使用'ax.annotate( '测试',(df5.index正常运行[1],DF5 [ 'SOLD_PRICE'] [1]),.. 。。。至少如果你的'DataFrame'的索引是'DatetimeIndex'。 – hooy

回答

12

您可以用DataFrameindex属性访问索引值。所以,你可以简单地使用

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

这给(根据您的样本数据)以下的输出:

enter image description here

+1

非常有帮助,谢谢! – dartdog