def plot_stoch_indicator(price,sma,stochk,file_name):
plt.clf()
fig = plt.figure()
ax = fig.add_subplot(211)
ax.set(title = 'AAPL with Stochastic Indicator')
ax.plot(price,label = 'AAPL Price')
ax.plot(sma,label = 'SMA(21)')
#ax.plot(upper_band, label = 'upper_band', color='r')
#ax.plot(bottom_band,label = 'bottom_band',color='r')
ax.set_ylabel('Price')
#ax.set_ylim([0,2])
#start, end = ax.get_xlim()
#ax.xaxis.set_ticks(np.arange(start,end,90))
L = plt.legend()
L.get_texts()[0].set_text('AAPL Price')
L.get_texts()[0].set_text('SMA(21)')
#L.get_texts()[1].set_text('Upper_band')
#L.get_texts()[2].set_text('Lower_band')
ax.tick_params(labelbottom='off')
ax.legend(loc = 'upper center',bbox_to_anchor = (0.55,1.0), prop = {'size':7})
###create font properties
#fontP = FontProperties()
#fontP.set_size('small')
#plt.legend([ax], "title",prop = fontP)
ax1 = fig.add_subplot(212)
ax1.plot(stochk,label = 'stochk',color = 'r')
#ax1.plot(stochd,label = 'stochd', color = 'green')
ax1.set_ylabel('Stochastic Oscillator')
ax1.set_xlabel('Date')
ax1.axhline(20.0, color = 'black')
ax1.axhline(80.0, color = 'black')
#start1, end1 = ax1.get_xlim()
#ax1.xaxis.set_ticks(np.arange(start,end,90))
fig.subplots_adjust(hspace=0.05)#,left = 0.2, right = 1.0, top = 0.2, bottom = 0.1)
plt.xticks(rotation=30)
plt.savefig(file_name)
#plt.show()
indicators.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录