将箭头添加到股票图表

时间:2013-10-03 16:16:37

标签: python matplotlib pandas ipython

我使用以下代码显示库存数据:

from pandas.io.data import get_data_yahoo
import matplotlib.pyplot as plt 
data = get_data_yahoo("ADS", start = '2012-01-01', end = '2012-12-31')[['Close','Volume']] 
data.plot(subplots = True, figsize = (8, 8)); 
plt.title('Adidas-Aktie 2012')
plt.legend(loc = 'best')
plt.show()

在某些日期位置,我想添加直接指向图表的箭头。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

尝试,

 from pandas.io.data import get_data_yahoo
 import matplotlib.pyplot as plt 
 data = get_data_yahoo("ADS", start = '2012-01-01', end = '2012-12-31' [['Close','Volume']] 
 ax = data.plot(subplots = True, figsize = (8, 8)); 
 plt.title('Adidas-Aktie 2012')
 plt.legend(loc = 'best')
 ax[0].annotate('your text',xy =(locx,locy), xytext=(locx,locy), arrowprops = dict(facecolor = 'black')) # assuming the you want to annotate the first plot
 plt.show()

在上面的代码中,(locx,locy)是您想要注释的文本的位置