def plot_ohlc_multiple_timeframe(stk, subset=None):
'''
>>> plot_ohlc_multiple_timeframe(stk, subset=('2015-11-10','2015-11-11'))
>>> plot_ohlc_multiple_timeframe(stk, None)
'''
#subset=None
fig,ax=plt.subplots()
for attr in map(lambda x: 'ohlc_'+x, freqs[:2]):
if subset is not None: print('subset={}, {}'.format(*subset))
if subset is not None:
ohlc = stk.__getattribute__(attr).loc[subset[0]:subset[1],]
if attr=='ohlc_1d':
midnight = ohlc.index + datetime.timedelta(hours=-15)
noon = ohlc.index + datetime.timedelta(hours=-3)
else:
ohlc = stk.__getattribute__(attr)
if attr=='ohlc_1d':
midnight = ohlc.index + datetime.timedelta(hours=-15)
noon = ohlc.index + datetime.timedelta(hours=-3)
x = mpl.dates.date2num(ohlc.index)
ax.plot(x, ohlc.close, label=attr[5:])
#print(stk.__getattribute__(attr).close[:2])
x = mpl.dates.date2num(midnight)
y1,y2= ax.get_ylim()
ax.vlines(x,y1,y2, color='k', lw=0.1, label='子夜')
x = mpl.dates.date2num(noon)
ax.vlines(x,y1,y2, color='c', lw=0.3, label='中午')
#'xtls = ax.get_xmajorticklabels()
#_new_t = mpl.dates.num2date(t._x) #.strftime('%Y\n%m%d')
xticks = ax.get_xticks()
if subset is not None:
new_t= [mpl.dates.num2date(xtick).strftime('%Y\n%m%d\n%H:%M') for xtick in xticks]
else:
new_t= [mpl.dates.num2date(xtick).strftime('%Y\n%m%d') for xtick in xticks]
ax.set_xticklabels(new_t)
ax.legend()
title = '日线分钟线欢聚一堂\n'
title += '证券名称: {}, 时间段: {}, {}'.format(stk.dname, ohlc.index[0], ohlc.index[-1])
fig.suptitle(title, fontsize=18)
fig.set_size_inches(18,8)