.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_plot/plot_timeslice.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_plot_plot_timeslice.py: How to Create Time Slices ========================= In this example we show how to create a filled contourplot of transient data over a sampling line. For this purpose we use a component transport example from the ogs benchmark gallery (https://www.opengeosys.org/docs/benchmarks/hydro-component/elder/). To see this benchmark results over all timesteps have a look at :ref:`sphx_glr_auto_examples_howto_plot_plot_animation.py`. .. GENERATED FROM PYTHON SOURCE LINES 15-16 Let's load the data which we want to investigate. .. GENERATED FROM PYTHON SOURCE LINES 18-26 .. code-block:: Python import numpy as np import ogstools as ot from ogstools import examples mesh_series = examples.load_meshseries_CT_2D_XDMF().scale(time=("s", "a")) si = ot.variables.saturation .. GENERATED FROM PYTHON SOURCE LINES 27-28 Now we setup two sampling lines. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python pts_vert = np.linspace([25, 0, -75], [25, 0, 75], num=300) pts_diag = np.linspace([25, 0, 75], [100, 0, 0], num=300) fig = mesh_series.mesh(-1).plot_contourf(si, vmin=0) fig.axes[0].plot(pts_vert[:, 0], pts_vert[:, 2], "-k", linewidth=3) fig.axes[0].plot(pts_diag[:, 0], pts_diag[:, 2], "-.k", linewidth=3) .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_001.png :alt: plot timeslice :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 37-39 Here, we first show a regular line sample plot for the vertical sampling line for each timestep. .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: Python ms_vert = ot.MeshSeries.extract_probe(mesh_series, pts_vert) labels = [f"{tv:.1f} a" for tv in ms_vert.timevalues] fig = ot.plot.line(ms_vert, si, "z", labels=labels, colors="coolwarm") fig.tight_layout() .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_002.png :alt: plot timeslice :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-51 As the above kind of plot is getting cluttered for lots of timesteps we provide a function to create a filled contour plot over the transient data. The function :meth:`~ogstools.meshlib.mesh_series.MeshSeries.plot_time_slice` creates a heatmap over time and space. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python fig = ms_vert.plot_time_slice("time", "z", si, vmin=0, vmax=100) .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_003.png :alt: plot timeslice :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-58 The stepping in this heatmap corresponds to the individual timesteps. To create a smoother image, we can resample the MeshSeries to more timesteps. .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python ms_vert_fine = ot.MeshSeries.resample(ms_vert, np.linspace(0, 4.2, 300)) fig = ms_vert_fine.plot_time_slice("time", "z", si, vmin=0, vmax=100) .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_004.png :alt: plot timeslice :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-66 You can also change the order of the arguments for spatial coordinate and time to flip the x- and y-axis. .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python ms_diag = ot.MeshSeries.extract_probe(mesh_series, pts_diag) ms_diag_fine = ot.MeshSeries.resample(ms_diag, np.linspace(0, 4.2, 300)) fig = ms_diag_fine.plot_time_slice("x", "time", si, vmin=0, vmax=100) fig.axes[0].invert_yaxis() .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_005.png :alt: plot timeslice :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_timeslice_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.597 seconds) .. _sphx_glr_download_auto_examples_howto_plot_plot_timeslice.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://binder.opengeosys.org/v2/gh/bilke/binder-ogs-requirements/6.5.6-0.7.1?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgitlab.opengeosys.org%252Fogs%252Ftools%252Fogstools%26urlpath%3Dlab%252Ftree%252Fogstools/docs/examples/howto_plot/plot_timeslice.py :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_timeslice.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_timeslice.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_timeslice.zip `