.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshplotlib/plot_xy_labels_with_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_meshplotlib_plot_xy_labels_with_shared_axes.py: Labeling directional shared axes ================================= .. sectionauthor:: Feliks Kiszkurno (Helmholtz Centre for Environmental Research GmbH - UFZ) .. warning:: This example discusses functionality that may experience breaking changes in the near future! For this example we load a 2D meshseries from within the ``meshplotlib`` examples. This tutorial covers automatic labeling the directional axes (X and Y) under various conditions (shared and nor shared X and Y axes). .. GENERATED FROM PYTHON SOURCE LINES 15-16 Import Python packages, change some settings and load example data set .. GENERATED FROM PYTHON SOURCE LINES 16-38 .. code-block:: Python import matplotlib.pyplot as plt from ogstools import examples from ogstools.meshlib import difference from ogstools.meshplotlib import ( clear_labels, label_spatial_axes, plot, setup, ) from ogstools.propertylib.properties import temperature plt.rcParams.update({"font.size": 32}) setup.reset() setup.length.output_unit = "km" setup.combined_colorbar = False meshseries = examples.load_meshseries_THM_2D_PVD() mesh_a = meshseries.read(0) mesh_b = meshseries.read(1) .. GENERATED FROM PYTHON SOURCE LINES 39-42 First, by default (without shared axes) both X and Y axes will be labeled automatically. The default is that both axes are shared and this will be respected. .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: Python fig = plot([mesh_a, mesh_b], temperature) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_001.png :alt: plot xy labels with shared axes :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-52 On user provided figure and axis, this behaviour is different. To allow for more complex combinations of plot functions, meshseries and process variables, the axis belonging to specific subplot has to be passed. In this case the default is to plot labels on each axis regardless of whether it is share or not. .. GENERATED FROM PYTHON SOURCE LINES 52-62 .. code-block:: Python fig, ax = plt.subplots(2, 2, figsize=(40, 20), sharex=True, sharey=True) plot(mesh_a, temperature, fig=fig, ax=ax[0][0]) plot(mesh_b, temperature, fig=fig, ax=ax[1][0]) diff_ab = difference(mesh_a, mesh_b, temperature) diff_ba = difference(mesh_b, mesh_a, temperature) plot(diff_ab, temperature, fig=fig, ax=ax[0][1]) plot(diff_ba, temperature, fig=fig, ax=ax[1][1]) fig.tight_layout() .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_002.png :alt: plot xy labels with shared axes :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 63-67 If user wishes to have labels respecting shared axes, they need to be first removed and applied again. Meshplotlib provides two function that make it easy: clear_labels and label_spatial_axes. They have to be called after the last plot related function call. .. GENERATED FROM PYTHON SOURCE LINES 67-76 .. code-block:: Python fig, ax = plt.subplots(2, 2, figsize=(40, 20), sharex=True, sharey=True) plot(mesh_a, temperature, fig=fig, ax=ax[0][0]) plot(mesh_b, temperature, fig=fig, ax=ax[1][0]) plot(difference(mesh_a, mesh_b, temperature), temperature, fig=fig, ax=ax[0][1]) plot(difference(mesh_b, mesh_a, temperature), temperature, fig=fig, ax=ax[1][1]) clear_labels(ax) label_spatial_axes(ax) fig.tight_layout() .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_003.png :alt: plot xy labels with shared axes :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_xy_labels_with_shared_axes_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.536 seconds) .. _sphx_glr_download_auto_examples_howto_meshplotlib_plot_xy_labels_with_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_xy_labels_with_shared_axes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_xy_labels_with_shared_axes.py `