matplotlib share xaxis with yaxis from another plot

Viewed 478

If I want to tie the x and y axis of two separate axes together so that they zoom together I usually do something like this:

fig = plt.figure()
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122,sharex=ax1, sharey=ax1)

But I don't know how to share the xaxis of one plot with the yaxis of another plot. For example the xaxis of one plot is 'time' and I want to share that with the yaxis of another plot which also represents 'time'. Something like this (which doesn't work...):

ax2 = fig.add_subplot(122,sharex=ax1.yaxis, sharey=ax1.xaxis)

Thanks

1 Answers

I would be doing something like this,

fig, axs = plt.subplots(3, sharex=True, sharey=True) //Here
fig.suptitle('Sharing both axes')
axs[0].plot(x, y ** 2)
axs[1].plot(x, 0.3 * y, 'o')
axs[2].plot(x, y, '+')

##As per matplotlib docs and works fine for me too Another way is you can superimpose too.

Related