Plotting different process variables on already existing Matplotlib figures / axes#

Section author: 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.

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

Compare different variables#

It is possible to plot various variables in different subplots of the same figure:

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()
plot with custom fig ax

Plot two time steps and their difference#

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:

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()
$T(\mathrm{t}_{0})$, $T(\mathrm{t}_{end})$, $T(\mathrm{t}_{end})$-$T(\mathrm{t}_{0})$

Total running time of the script: (0 minutes 2.135 seconds)