.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshplotlib/plot_with_custom_fig_ax.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_with_custom_fig_ax.py: Plotting different process variables on already existing Matplotlib figures / axes ================================================================================== .. sectionauthor:: Feliks Kiszkurno (Helmholtz Centre for Environmental Research GmbH - UFZ) For this example we load a 2D meshseries from within the ``meshplotlib`` examples. This tutorial covers using meshplotlib to plot meshseries data using Matplotlib objects for Figure and / or Axis. This is useful if different plotting functions from Meshplotlib are to be used on different subplots within the same figure. .. GENERATED FROM PYTHON SOURCE LINES 15-16 Import Python packages, change some settings and load example data set .. GENERATED FROM PYTHON SOURCE LINES 16-30 .. code-block:: Python import matplotlib.pyplot as plt from ogstools.meshlib import difference from ogstools.meshplotlib import examples, plot, setup from ogstools.propertylib import presets plt.rcParams.update({"font.size": 32}) setup.reset() setup.length.output_unit = "km" meshseries = examples.meshseries_THM_2D .. GENERATED FROM PYTHON SOURCE LINES 31-34 It is possible to plot various process parameter in different subplots of the same figure. But each mesh series and parameter pair need a separate call of plot function: .. GENERATED FROM PYTHON SOURCE LINES 34-42 .. code-block:: Python setup.combined_colorbar = False fig, ax = plt.subplots(2, 1, figsize=(15, 15)) plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0]) plot(meshseries.read(1), presets.displacement, fig=fig, ax=ax[1]) fig.suptitle("Compare temperature and displacement") fig.tight_layout() .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_with_custom_fig_ax_001.png :alt: Compare temperature and displacement :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_with_custom_fig_ax_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-46 The same way difference between process variables at different time steps can be plotted. Color bars can be drawn automatically, if user provides both Figure and Axes objects: .. GENERATED FROM PYTHON SOURCE LINES 46-59 .. code-block:: Python fig, ax = plt.subplots(3, 1, figsize=(20, 30)) plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0]) ax[0].set_title(r"$T(\mathrm{t}_{0})$") plot(meshseries.read(1), presets.temperature, fig=fig, ax=ax[1]) ax[1].set_title(r"$T(\mathrm{t}_{end})$") diff_mesh = difference( meshseries.read(1), meshseries.read(0), presets.temperature ) plot(diff_mesh, presets.temperature, fig=fig, ax=ax[2]) ax[2].set_title(r"$T(\mathrm{t}_{end})$-$T(\mathrm{t}_{0})$") fig.suptitle("Plot two time steps and their difference - with colorbars") fig.tight_layout() .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_with_custom_fig_ax_002.png :alt: Plot two time steps and their difference - with colorbars, $T(\mathrm{t}_{0})$, $T(\mathrm{t}_{end})$, $T(\mathrm{t}_{end})$-$T(\mathrm{t}_{0})$ :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_with_custom_fig_ax_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.135 seconds) .. _sphx_glr_download_auto_examples_howto_meshplotlib_plot_with_custom_fig_ax.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_with_custom_fig_ax.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_with_custom_fig_ax.py `