.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_plot/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_plot_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) This tutorial covers plotting meshseries data using user defined matplotlib objects for figure and / or axes. This is useful if different plotting functions ogstools are to be used on different subplots within the same figure. .. GENERATED FROM PYTHON SOURCE LINES 13-22 .. code-block:: Python import matplotlib.pyplot as plt import ogstools as ogs from ogstools import examples meshseries = examples.load_meshseries_THM_2D_PVD() ogs.plot.setup.combined_colorbar = False .. GENERATED FROM PYTHON SOURCE LINES 23-25 Compare different variables ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-29 It is possible to plot various variables in different subplots of the same figure: .. GENERATED FROM PYTHON SOURCE LINES 29-35 .. code-block:: Python fig, ax = plt.subplots(2, 1, figsize=(15, 15)) meshseries.mesh(0).plot_contourf(ogs.variables.temperature, fig=fig, ax=ax[0]) meshseries.mesh(1).plot_contourf(ogs.variables.displacement, fig=fig, ax=ax[1]) fig.tight_layout() .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_with_custom_fig_ax_001.png :alt: plot with custom fig ax :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_with_custom_fig_ax_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-38 Plot two time steps and their difference ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-43 We can use the same approach to plot the difference between 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 43-58 .. code-block:: Python fig, ax = plt.subplots(3, 1, figsize=(20, 30)) meshseries.mesh(0).plot_contourf(ogs.variables.temperature, fig=fig, ax=ax[0]) meshseries.mesh(1).plot_contourf(ogs.variables.temperature, fig=fig, ax=ax[1]) diff_mesh = meshseries.mesh(1).difference( meshseries.mesh(0), ogs.variables.temperature ) diff_mesh.plot_contourf(ogs.variables.temperature, fig=fig, ax=ax[2]) ax[0].set_title(r"$T(\mathrm{t}_{0})$") ax[1].set_title(r"$T(\mathrm{t}_{end})$") ax[2].set_title(r"$T(\mathrm{t}_{end})$-$T(\mathrm{t}_{0})$") fig.tight_layout() .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_with_custom_fig_ax_002.png :alt: $T(\mathrm{t}_{0})$, $T(\mathrm{t}_{end})$, $T(\mathrm{t}_{end})$-$T(\mathrm{t}_{0})$ :srcset: /auto_examples/howto_plot/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 1.681 seconds) .. _sphx_glr_download_auto_examples_howto_plot_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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_with_custom_fig_ax.zip `