【发布时间】:2013-07-26 21:40:58
【问题描述】:
鉴于DataFrame 喜欢:
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')
我生成如下图:
我不知道如何让轴附加注释?
这个例子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...
【问题讨论】:
-
似乎没有使用带有 Dataframe 索引的 Dataframe?
-
对于 pandas 0.11.0 和 matplotlib 1.2.1,如果您使用
ax.annotate('Test', (df5.index[1], df5['SOLD_PRICE'][1]), ...,它似乎可以正常运行。至少如果您的DataFrame的索引是DatetimeIndex。 -
@nordev 美丽!!请张贴作为答案,以便我可以正确标记!只是无法解决 DF 索引访问语法!非常感谢
标签: python matplotlib pandas