.. _sphx_glr_gallery_recipes_share_axis_lims_views.py: Sharing axis limits and views ============================= It's common to make two or more plots which share an axis, e.g., two subplots with time as a common axis. When you pan and zoom around on one, you want the other to move around with you. To facilitate this, matplotlib Axes support a ``sharex`` and ``sharey`` attribute. When you create a :func:`~matplotlib.pyplot.subplot` or :func:`~matplotlib.pyplot.axes` instance, you can pass in a keyword indicating what axes you want to share with .. image:: /gallery/recipes/images/sphx_glr_share_axis_lims_views_001.png :align: center .. code-block:: python import numpy as np import matplotlib.pyplot as plt t = np.arange(0, 10, 0.01) ax1 = plt.subplot(211) ax1.plot(t, np.sin(2*np.pi*t)) ax2 = plt.subplot(212, sharex=ax1) ax2.plot(t, np.sin(4*np.pi*t)) .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: https://static.mybinder.org/badge.svg :target: https://mybinder.org/v2/gh/choldgraf/matplotlib/gh-pages?filepath=_downloads/share_axis_lims_views.ipynb :width: 150 px .. container:: sphx-glr-download :download:`Download Python source code: share_axis_lims_views.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: share_axis_lims_views.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_