Matplotlib/Pyplot: How to zoom subplots together?

后端 未结 3 429
离开以前
离开以前 2020-12-07 18:21

I have plots of 3-axis accelerometer time-series data (t,x,y,z) in separate subplots I\'d like to zoom together. That is, when I use the \"Zoom to Rectangle\" tool on one p

相关标签:
3条回答
  • 2020-12-07 18:50

    Interactively this works on separate axes

    for ax in fig.axes:
        ax.set_xlim(0, 50)
    fig.draw()
    
    0 讨论(0)
  • 2020-12-07 18:57

    You can also do this with plt.subplots, if that's your style.

    fig, ax = plt.subplots(3, 1, sharex=True, sharey=True)
    
    0 讨论(0)
  • 2020-12-07 19:05

    The easiest way to do this is by using the sharex and/or sharey keywords when creating the axes:

    from matplotlib import pyplot as plt
    
    ax1 = plt.subplot(2,1,1)
    ax1.plot(...)
    ax2 = plt.subplot(2,1,2, sharex=ax1)
    ax2.plot(...)
    
    0 讨论(0)
提交回复
热议问题