def plot_entry(fig, exit_profit, entry_best, entry_worst, entry_nbar_best, entry_nbar_worst, nbar, binwidth=1):
fig.canvas.set_window_title(u'??')
axescolor = '#f6f6f6' # the axes background color
left, width = 0.1, 0.8
rect1 = [left, 0.7, width, 0.2]#left, bottom, width, height
rect2 = [left, 0.3, width, 0.4]
rect3 = [left, 0.1, width, 0.2]
ax1 = fig.add_axes(rect1, axisbg=axescolor)
ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex = ax1)
ax3 = fig.add_axes(rect3, axisbg=axescolor, sharex = ax1)
(entry_best-exit_profit).plot(ax=ax1, kind='bar', grid = False, use_index = False, label=u"?")
entry_worst.plot(ax=ax1, kind='bar', grid = False, use_index = False, color = 'y', label=u"?")
if nbar>0:
entry_nbar_best.plot(ax=ax3, kind='bar', color='red', grid=False, use_index=False, label=u"%s"%nbar)
#ax3.bar(range(len(entry_nbar_best)), entry_nbar_best, color='r', label=u"%s"%nbar)
entry_nbar_worst.plot(ax=ax3, kind='bar', color='y', grid=False, use_index=False, label=u"%s"%nbar)
temp = entry_nbar_worst[entry_nbar_worst<0]
ax3.plot(range(len(entry_nbar_best)), [temp.mean()]*len(entry_nbar_best), 'y--', label=u"?: %s"%temp.mean())
temp = entry_nbar_best[entry_nbar_best>0]
ax3.plot(range(len(entry_nbar_best)), [temp.mean()]*len(entry_nbar_best),
'r--', label=u'?: %s'%temp.mean() )
ax3.legend(loc='upper left',prop=font).get_frame().set_alpha(0.5)
for i in xrange(len(exit_profit)):
if(entry_best[i]>0 and exit_profit[i]>0):
px21 = ax2.bar(i, exit_profit[i], width=binwidth, color='blue')
px22 = ax2.bar(i, entry_best[i]-exit_profit[i], width=binwidth, color='red', bottom = exit_profit[i])
elif(entry_best[i]<0 and exit_profit[i]<0):
ax2.bar(i, entry_best[i], width=binwidth, color='red')
ax2.bar(i, exit_profit[i]-entry_best[i], width=binwidth, color='blue', bottom = entry_best[i])
else:
ax2.bar(i, entry_best[i], width=binwidth, color='red')
ax2.bar(i, exit_profit[i], width=binwidth, color='blue')
ax2.legend((px21[0], px22[0]), (u'??', u'?'), loc='upper left', prop=font).get_frame().set_alpha(0.5)
ax1.legend(loc='upper left', prop=font).get_frame().set_alpha(0.5)
ax1.set_ylabel(u"???", fontproperties = font)
ax2.set_ylabel(u"??", fontproperties = font)
for ax in ax1, ax2, ax3:
#if ax!=ax3:
ax.set_xticklabels([])
ax3.set_xlabel("")
ax1.set_title(u"??", fontproperties=font_big)
c1 = Cursor(ax2, useblit=True, color='red', linewidth=1, vertOn = True, horizOn = True)
multi = MultiCursor(fig.canvas, fig.axes, color='r', lw=1, horizOn=False, vertOn=True)
#handle = EventHandler(exit_profit, fig)
#fig.canvas.mpl_connect('motion_notify_event', handle.on_move)
#fig.canvas.mpl_connect('pick_event', handle.on_pick)
def format_coord(x, y):
""" ???? """
i = int(x)/1
c = pd.to_datetime(exit_profit.index[i]).strftime("%Y-%m-%d %H:%M:%S") + " Profit: %s MAE: %s"%(exit_profit[i], entry_worst[i])
return str(c)
ax1.format_coord = format_coord
ax2.format_coord = format_coord
ax3.format_coord = format_coord
return [ax1, ax2, ax3], [multi, c1]
评论列表
文章目录