I am creating a figure with 2 subplots using the following code:
fig, (ax1, ax2) = plt.subplots(2, sharex = True, figsize=(20, 6))
mpf.candlestick_ohlc(ax1,quotes, width=0.01)
ax1.xaxis_date()
ax1.xaxis.set_major_locator(mpl.dates.DayLocator(interval=1) )
ax1.xaxis.set_major_formatter(mpl.dates.DateFormatter('%a, %b %d \'%y'))
ax1.xaxis.set_minor_locator(mpl.dates.HourLocator(byhour=range(0,24,4)))
ax1.xaxis.set_minor_formatter(mpl.dates.DateFormatter('%-H'))
ax1.grid(True)
ax1.grid(b=True, which='minor', color='0.7', linestyle='dotted')
ax2.tick_params(direction='out', pad=15)
majors=ax1.xaxis.get_majorticklocs()
chart_start, chart_end = (ax1.xaxis.get_view_interval()[0],ax1.xaxis.get_view_interval()[1])
for major in majors:
ax1.axvspan(max (chart_start, major-(0.3333)),min(chart_end, major+(0.3333)),color="0.95", zorder=-1 )
plt.bar(quotes[:,0] , quotes[:, 5], width = 0.01)
plt.show()
Here the resulting figure:
I would like the subplot at the bottom to have the same grid, major/ minor ticks and axvspan as the subplot above. I could rewrite all the ax1... lines changing ax1 for ax2 , but i suspect there might be a way to assign the different elements (ie grid, minor/major ticks and axvspan) to both axes in 1 go?
