I'm using matplotlib.axes.Axes.twinx
to have a shared x-axis in matplotlib.
Is it possible to plot data on the second y-axis behind (in the background) of the data plotted on the first y-axix?
E.g.
from matplotlib import pyplot as plt
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax2.fill_between([0,1],[0,0],[0.5,0.5], color='0.7')
ax1.plot([0,1],[0,1], color='r')
ax2.set_ylim([0,1])
This gives the following figure:
I would like to have the red line in front of the grey box, while keeping the left axis the one representing the red line. The z-order argument does not seem to work to set the order across different axes instances.