.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/subplots_axes_and_figures/ganged_plots.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_subplots_axes_and_figures_ganged_plots.py: ========================== Creating adjacent subplots ========================== To create plots that share a common axis (visually) you can set the hspace between the subplots to zero. Passing sharex=True when creating the subplots will automatically turn off all x ticks and labels except those on the bottom axis. In this example the plots share a common x-axis, but you can follow the same logic to supply a common y-axis. .. GENERATED FROM PYTHON SOURCE LINES 14-41 .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_ganged_plots_001.png :alt: ganged plots :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_ganged_plots_001.png, /gallery/subplots_axes_and_figures/images/sphx_glr_ganged_plots_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np t = np.arange(0.0, 2.0, 0.01) s1 = np.sin(2 * np.pi * t) s2 = np.exp(-t) s3 = s1 * s2 fig, axs = plt.subplots(3, 1, sharex=True) # Remove vertical space between axes fig.subplots_adjust(hspace=0) # Plot each graph, and manually set the y tick values axs[0].plot(t, s1) axs[0].set_yticks(np.arange(-0.9, 1.0, 0.4)) axs[0].set_ylim(-1, 1) axs[1].plot(t, s2) axs[1].set_yticks(np.arange(0.1, 1.0, 0.2)) axs[1].set_ylim(0, 1) axs[2].plot(t, s3) axs[2].set_yticks(np.arange(-0.9, 1.0, 0.4)) axs[2].set_ylim(-1, 1) plt.show() .. _sphx_glr_download_gallery_subplots_axes_and_figures_ganged_plots.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ganged_plots.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ganged_plots.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_