.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshplotlib/plot_meshplotlib_2d.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_meshplotlib_2d.py: Visualizing 2D model data ========================= .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) For this example we load a 2D meshseries from within the ``meshplotlib`` examples. In the ``meshplotlib.setup`` we can provide a dictionary to map names to material ids. First, let's plot the material ids (cell_data). Per default in the setup, this will automatically show the element edges. .. GENERATED FROM PYTHON SOURCE LINES 14-23 .. code-block:: Python import ogstools.meshplotlib as mpl from ogstools import examples from ogstools.propertylib import properties mpl.setup.reset() mpl.setup.length.output_unit = "km" mpl.setup.material_names = {i + 1: f"Layer {i+1}" for i in range(26)} mesh = examples.load_meshseries_THM_2D_PVD().read(1) .. GENERATED FROM PYTHON SOURCE LINES 24-31 To read your own data as a mesh series you can do: .. code-block:: python from ogstools.meshlib import MeshSeries mesh_series = MeshSeries("filepath/filename_pvd_or_xdmf") .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python fig = mpl.plot(mesh, properties.material_id) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_001.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-39 Now, let's plot the temperature field (point_data) at the first timestep. The default temperature property from the `propertylib` reads the temperature data as Kelvin and converts them to degrees Celsius. .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python fig = mpl.plot(mesh, properties.temperature) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_002.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-45 We can also plot components of vector properties: .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: Python fig = mpl.plot(mesh, properties.displacement[0]) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_003.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python fig = mpl.plot(mesh, properties.displacement[1]) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_004.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 53-54 This example has hydraulically deactivated subdomains: .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: Python fig = mpl.plot(mesh, properties.pressure.get_mask()) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_005.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-60 Let's plot the fluid velocity field. .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python fig = mpl.plot(mesh, properties.velocity) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_006.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-66 Let's plot it again, this time log-scaled. .. GENERATED FROM PYTHON SOURCE LINES 68-71 .. code-block:: Python mpl.setup.log_scaled = True mpl.setup.p_min = -8 fig = mpl.plot(mesh, properties.velocity) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_007.png :alt: plot meshplotlib 2d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_2d_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.276 seconds) .. _sphx_glr_download_auto_examples_howto_meshplotlib_plot_meshplotlib_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_meshplotlib_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_meshplotlib_2d.py `