.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plotting/custom_figure_layout.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_auto_examples_plotting_custom_figure_layout.py: ======================= Creating Custom Layouts ======================= Custom layouts for hyperspy figures can be created using the :class:`matplotlib.figure.SubFigure` class. Passing the ``fig`` argument to the :meth:`~.api.signals.BaseSignal.plot` method of a hyperspy signal object will target that figure instead of creating a new one. This is useful for creating custom layouts with multiple subplots. .. Note:: Plotting data with subfigures is slower than using separates figures. .. GENERATED FROM PYTHON SOURCE LINES 14-27 .. code-block:: Python # Creating a simple layout with two subplots import matplotlib.pyplot as plt import hyperspy.api as hs import numpy as np rng = np.random.default_rng() s = hs.signals.Signal2D(rng.random((10, 10, 10, 10))) fig = plt.figure(figsize=(10, 5), layout="constrained") subfigs = fig.subfigures(1, 2, wspace=0.07) s.plot(navigator_kwds=dict(fig=subfigs[0]), fig=subfigs[1]) .. image-sg:: /auto_examples/plotting/images/sphx_glr_custom_figure_layout_001.png :alt: Signal :srcset: /auto_examples/plotting/images/sphx_glr_custom_figure_layout_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 28-40 .. code-block:: Python # Sharing a navigator between two hyperspy signals s = hs.signals.Signal2D(rng.random((10, 10, 10, 10))) s2 = hs.signals.Signal2D(rng.random((10, 10, 50, 50))) fig = plt.figure(figsize=(8, 7), layout="constrained") head_figures = fig.subfigures(1, 2, wspace=0.07) signal_figures = head_figures[1].subfigures(2, 1, hspace=0.07) s.plot(navigator_kwds=dict(fig=head_figures[0], colorbar=None), fig=signal_figures[0]) s2.plot(navigator=None, fig=signal_figures[1], axes_manager=s.axes_manager) .. image-sg:: /auto_examples/plotting/images/sphx_glr_custom_figure_layout_002.png :alt: Signal, Signal :srcset: /auto_examples/plotting/images/sphx_glr_custom_figure_layout_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-42 sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.814 seconds) .. _sphx_glr_download_auto_examples_plotting_custom_figure_layout.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: custom_figure_layout.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: custom_figure_layout.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: custom_figure_layout.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_