.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_plot/plot_shared_axes.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_howto_plot_plot_shared_axes.py: Shared axes =========== .. sectionauthor:: Feliks Kiszkurno (Helmholtz Centre for Environmental Research GmbH - UFZ) In this example we show how to create filled contourplots on a figure with subplots having shared axes. .. GENERATED FROM PYTHON SOURCE LINES 12-13 Import packages, load example data set and define often used variables. .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: Python import matplotlib.pyplot as plt import ogstools as ogs from ogstools import examples meshseries = examples.load_meshseries_THM_2D_PVD() mesh_0 = meshseries.mesh(0) mesh_1 = meshseries.mesh(1) variable = ogs.variables.temperature .. GENERATED FROM PYTHON SOURCE LINES 24-27 If you pass multiple meshes to :py:func:`ogstools.plot.contourf` by default both x and y axes will shared. Thus, only the outer axes get axes labels and tick label. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python fig = ogs.plot.contourf([mesh_0, mesh_1], variable) .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_shared_axes_001.png :alt: plot shared axes :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_shared_axes_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 31-33 On user defined figure and axis the axis belonging to specific subplot has to be passed. For technical reasons, the axes label are present on all subplots. .. GENERATED FROM PYTHON SOURCE LINES 33-44 .. code-block:: Python fig, axs = plt.subplots(2, 2, figsize=(40, 17), sharex=True, sharey=True) diff_a = mesh_0.difference(mesh_1, variable) diff_b = mesh_1.difference(mesh_0, variable) ogs.plot.contourf(mesh_0, variable, fig=fig, ax=axs[0][0]) ogs.plot.contourf(mesh_1, variable, fig=fig, ax=axs[1][0]) ogs.plot.contourf(diff_a, variable, fig=fig, ax=axs[0][1]) ogs.plot.contourf(diff_b, variable, fig=fig, ax=axs[1][1]) fig.tight_layout() plt.show() .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_shared_axes_002.png :alt: plot shared axes :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_shared_axes_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-47 For custom figures, If they should only be present on the outer axes, they have to be adapted manually: .. GENERATED FROM PYTHON SOURCE LINES 47-55 .. code-block:: Python ax: plt.Axes for ax in axs[0, :]: ax.set_xlabel("") for ax in axs[:, -1]: ax.set_ylabel("") fig.tight_layout() fig .. rst-class:: sphx-glr-script-out .. code-block:: none
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.674 seconds) .. _sphx_glr_download_auto_examples_howto_plot_plot_shared_axes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_shared_axes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_shared_axes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_shared_axes.zip `