def _make_chart(df, chartfn, **kwargs):
fig = plt.figure()
ax1 = plt.subplot2grid((6, 4), (1, 0), rowspan=4, colspan=4)
ax1.grid(True)
plt.ylabel('Price')
plt.setp(plt.gca().get_xticklabels(), visible=False)
chartfn(df, ax1)
if 'lines' in kwargs:
_plot_lines(kwargs['lines'])
if 'band' in kwargs:
_plot_band(kwargs['band'])
if 'events' in kwargs:
_plot_events(kwargs['events'])
ax2 = plt.subplot2grid((6, 4), (5, 0), sharex=ax1, rowspan=1, colspan=4)
volume = df['volume']
pos = df['open'] - df['close'] <= 0 # mask
neg = df['open'] - df['close'] > 0
ax2.bar(volume[pos].index, volume[pos], color='red', width=0.4, align='center', alpha=0.5)
ax2.bar(volume[neg].index, volume[neg], color='green', width=0.4, align='center', alpha=0.5)
# ax2.bar(df.index, df.loc[:, 'volume'],align='center')
ax2.xaxis.set_major_locator(mticker.MaxNLocator(12))
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
if len(df.index) <= 500:
ax2.xaxis.set_minor_locator(mdates.DayLocator())
ax2.yaxis.set_ticklabels([])
ax2.grid(True)
plt.ylabel('Volume')
plt.xlabel('DateTime')
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
ax3 = plt.subplot2grid((6, 4), (0, 0), sharex=ax1, rowspan=1, colspan=4)
if 'tracks' in kwargs:
_plot_tracks(kwargs['tracks'])
ax3.yaxis.set_ticklabels([])
# ax3.yaxis.tick_right()
ax3.grid(True)
ax3.xaxis.set_visible(False)
ax3.set_ylabel('Observe')
plt.subplots_adjust(left=.09, bottom=.18, right=.94, top=0.94, wspace=.20, hspace=0)
if 'title' in kwargs:
plt.suptitle(kwargs['title'])
if 'fname' in kwargs:
plt.savefig(kwargs['fname'], bbox_inches='tight')
plt.show()
# plt.close()
评论列表
文章目录