Search code examples
pythonmatplotlibplot

link axis between different plot (no subplots) using matplotlib


I know there is a simple way to link the axis of different plot if they are subplots in the same figure this way :

import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212, sharex=ax1)

Is there a way to do the same link (when zooming on figure 1, I get the same zoom on figure 2 on one particular axis) when defining two different figures?

I want those graph to appear far from each other so I guess that I can't put them in the same figure.


Solution

  • You simply do the same thing, but with a different figure.

    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    fig2 = plt.figure()
    ax2 = fig2.add_subplot(111, sharex=ax1)