0

I have multiple plots created as below.

    fig, ax = plt.subplots()
    ax.plot(x,y)
    fig2, ax2 = plt.subplots()
    ax2.plot(x2,y2)
    fig3, ax3 = plt.subplots()
    ax3.plot(x3,y3)

This creates three figures, x, x2, x3 are time range. I want to make the xlim on all this plots equal to each other, so that when I zoom or pan in one graph it automatically update and show the same x (time) range in all.

One graph can act as master as well if this is not possible.

Currently I use this function in script (Jupyter) which I have to run after every interaction.

def syncplot():
    xlimax1=ax1.get_xlim()
    ax2.set_xlim(xlimax1[0],xlimax1[1])
    ax3.set_xlim(xlimax1[0],xlimax1[1])

syncplot()
  • 1
    Look at sharex, sharey .... https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.subplots.html – Scott Boston Mar 31 '22 at 14:53
  • Does that work on two separate figures?, I guess not, at lease didn't work when I tried. I need to have two separate figures, I know how to do it in the same figures with multiple axis (subplots). – Samir Chauhan Mar 31 '22 at 17:41

0 Answers0