.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/layouts/03_spanning_labels.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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_layouts_03_spanning_labels.py: Spanning labels with shared axes =============================== Demonstrate shared labels across a row of related subplots. Why UltraPlot here? ------------------- UltraPlot can span labels across subplot groups while keeping axis limits shared. This avoids manual ``fig.supxlabel`` placement and reduces label clutter. Key functions: :py:func:`ultraplot.subplots`, :py:meth:`ultraplot.gridspec.SubplotGrid.format`. See also -------- * :doc:`Subplots and layouts ` .. GENERATED FROM PYTHON SOURCE LINES 18-52 .. image-sg:: /gallery/layouts/images/sphx_glr_03_spanning_labels_001.png :alt: Spanning labels with shared axes, Condition 1, Condition 2, Condition 3, Condition 4, Condition 5 :srcset: /gallery/layouts/images/sphx_glr_03_spanning_labels_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import ultraplot as uplt rng = np.random.default_rng(21) x = np.linspace(0, 5, 300) layout = [[1, 2, 5], [3, 4, 5]] fig, axs = uplt.subplots(layout) for i, ax in enumerate(axs): trend = (i + 1) * 0.2 y = np.exp(-0.4 * x) * np.sin(2 * x + i * 0.6) + trend y += 0.05 * rng.standard_normal(x.size) ax.plot(x, y, lw=2) ax.fill_between(x, y - 0.15, y + 0.15, alpha=0.2) ax.set_title(f"Condition {i + 1}") # Share first 2 plots top left axs[:2].format( xlabel="Time (days)", ) axs[1, :2].format(xlabel="Time 2 (days)") axs[-1].format(xlabel="Time 3 (days)") axs.format( xlabel="Time (days)", ylabel="Normalized response", abc=True, abcloc="ul", suptitle="Spanning labels with shared axes", grid=False, ) fig.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.321 seconds) .. _sphx_glr_download_gallery_layouts_03_spanning_labels.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_spanning_labels.ipynb <03_spanning_labels.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_spanning_labels.py <03_spanning_labels.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_spanning_labels.zip <03_spanning_labels.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_