.. 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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_plot_plot_timeslice.py: How to Create Time Slices ========================= .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) 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 17-19 Let's load the data and create 3 different lines to sample over: vertical, horizontal and diagonal. .. GENERATED FROM PYTHON SOURCE LINES 19-34 .. code-block:: Python import numpy as np import ogstools as ogs from ogstools import examples mesh_series = examples.load_meshseries_CT_2D_XDMF() si = ogs.variables.saturation points_vert = np.linspace([25, 0, -75], [25, 0, 75], num=100) points_hori = np.linspace([0, 0, 60], [150, 0, 60], num=100) points_diag = np.linspace([25, 0, 75], [100, 0, 0], num=100) fig = mesh_series.mesh(-1).plot_contourf(si, vmin=0) fig.axes[0].plot(points_vert[[0, -1], 0], points_vert[[0, -1], 2], "-k2") fig.axes[0].plot(points_hori[[0, -1], 0], points_hori[[0, -1], 2], "--k2") fig.axes[0].plot(points_diag[[0, -1], 0], points_diag[[0, -1], 2], "-.k2") .. 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 35-37 The function plot_time_slice automatically detects if the line lies on a cardinal direction and labels the y-axes with the changing spatial dimension. .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python fig = mesh_series.plot_time_slice(si, points_vert, time_unit="a") .. 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 40-43 By default the plot is smoothened with interpolation. When deactivated, we see the raw sampled data. Be sure to adjust the number of sampling points if the MeshSeries contains a lot of timesteps. .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python fig = mesh_series.plot_time_slice( si, points_vert, time_unit="a", interpolate=False ) .. 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 48-49 The horizontal sampling line gets also labeled appropriately. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python fig = mesh_series.plot_time_slice(si, points_hori, time_unit="a") .. 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 52-56 If the line doesn't point in a cardinal direction the distance along the line is used for the y-axis by default. You can however, specify if you want to use spatial dimension via the argument "y_axis". This may be useful when plotting data of an edge / boundary of the mesh. .. GENERATED FROM PYTHON SOURCE LINES 56-57 .. code-block:: Python fig = mesh_series.plot_time_slice(si, points_diag, time_unit="a") .. 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 1.454 seconds) .. _sphx_glr_download_auto_examples_howto_plot_plot_timeslice.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. 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 `