I am familiar to using twinx()
to share an axis's x-axis with another subplot:
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(xdata1, ydata1)
ax2.plot(xdata2, ydata2)
This makes the y=0
axis line up between ax1
and ax2
, but the axes are still on separate subplots so they each get their own autoscaling to match whatever is plotted on them as normal. However, I have a situation where I need to create separate axes ax1
and ax2
on the different subplots, but with a specified offset between their x-axes - i.e. ax1
's y=y0
needs to line up with ax2
's y=0
, for some nonzero offset y0
, like this:
This post appears to be close to what I am after, but not quite the same. That example uses a secondary y-axis with a function relating its values to the primary y-axis. However, I need a separate subplot entirely with its own scaling just like twinx()
gives me.