.. 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_3d.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_3d.py: Visualizing 3D model data ========================= .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) For visualizing 3D data it might make sense to plot multiple views / slices. To create them we use ``pyvista`` as it provides all the necessary functionality. If we want to plot multiple meshes, they have to be in a 2D ``numpy`` array. The shape of this array determines the number of rows and columns in our plot. First, let's load 3D example data from ``pyvista`` and plot the only available dataset: "facies" with a native pyvista plot. .. GENERATED FROM PYTHON SOURCE LINES 16-28 .. code-block:: default import numpy as np from pyvista import examples import ogstools.meshplotlib as mpl from ogstools.propertylib import Scalar mpl.setup.reset() mesh = examples.load_channels() mesh.plot(cmap="bwr") data = Scalar("facies", categoric=True) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_001.png :alt: plot meshplotlib 3d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-31 Now, let's create multiple slices along the z axis and plot them with meshplotlib in a 2 by 2 grid. .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: default slices = np.reshape(list(mesh.slice_along_axis(n=4, axis="z")), (2, 2)) fig = mpl.plot(slices, data) for ax, slice in zip(fig.axes, np.ravel(slices)): ax.set_title(f"z = {slice.center[2]:.1f} {mpl.setup.length.data_unit}") .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_002.png :alt: z = 1.0 m, z = 33.7 m, z = 66.3 m, z = 99.0 m :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-39 We can also slice along the y-axis and plot the meshes in one row. .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: default slices = np.reshape(mesh.slice_along_axis(n=3, axis="y"), (1, -1)) fig = mpl.plot(slices, data) for ax, slice in zip(fig.axes, np.ravel(slices)): ax.set_title(f"y = {slice.center[1]:.1f} {mpl.setup.length.data_unit}") .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_003.png :alt: y = 2.5 m, y = 125.0 m, y = 247.5 m :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-48 Arbitrary oriented slices are also possible. They get projected to the cardinal plane, from which they have the least rotational offset. .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: default fig = mpl.plot(mesh.slice([1, -2, 0]), data) .. image-sg:: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_004.png :alt: plot meshplotlib 3d :srcset: /auto_examples/howto_meshplotlib/images/sphx_glr_plot_meshplotlib_3d_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.530 seconds) .. _sphx_glr_download_auto_examples_howto_meshplotlib_plot_meshplotlib_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_meshplotlib_3d.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_meshplotlib_3d.ipynb `