2017-04-10 19 views
2

df =註解與另一系列的一定值的曲線(指數爲datetime)

date   Close  Bullish 
2010-04-07 2.02  0 
2010-04-08 2.03  0 
2010-04-09 2.05  1 
2010-04-12 2.16  1 
2010-04-13 2.32  1 





fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(df.Close, '-') 
ax.annotate('Bullish', xy= , xytext=(1, 1.), 
     arrowprops=dict(facecolor='black', shrink=), 
     ) 

所以我繪製股票的收盤價,我想註釋字線圖「看漲','看漲'欄中有1個值的地方。

我對註解不太熟悉,所以我沒有太多。

謝謝。

回答

2

我想你錯過了使用matplotlib.dates和註釋。看到這個SO post

import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
    fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(df.Close, '-') 

for i in df.query('Bullish == 1').iterrows(): 
    ax.annotate('Bullish',xy=(mdates.date2num(i[0]),i[1][0]), xytext=(15,15), textcoords='offset points', 
     arrowprops=dict(facecolor='black')) 

plt.xticks(rotation=45) 

enter image description here

相關問題