.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_plot/plot_contourf_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_plot_plot_contourf_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 data: "facies" with a native pyvista plot. .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. code-block:: Python import numpy as np from pyvista import examples import ogstools as ogs mesh = examples.load_channels() data = ogs.variables.Scalar("facies", categoric=True) mesh.plot(cmap="bwr") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_001.png :alt: plot contourf 3d :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 27-28 Let's create multiple slices along the z axis and plot them in a 2 by 2 grid. .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python slices = np.reshape(list(mesh.slice_along_axis(n=4, axis="z")), (2, 2)) fig = ogs.plot.contourf(slices, data) for ax, slice in zip(fig.axes, np.ravel(slices), strict=False): ax.set_title(f"z = {slice.center[2]:.1f}") .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_002.png :alt: z = 1.0, z = 33.7, z = 66.3, z = 99.0 :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-36 We can also slice along the y-axis and plot the meshes in one row. .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. code-block:: Python slices = np.reshape(mesh.slice_along_axis(n=3, axis="y"), (1, -1)) fig = ogs.plot.contourf(slices, data) for ax, slice in zip(fig.axes, np.ravel(slices), strict=False): ax.set_title(f"y = {slice.center[1]:.1f}") .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_003.png :alt: y = 2.5, y = 125.0, y = 247.5 :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-45 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 45-47 .. code-block:: Python fig = ogs.plot.contourf(mesh.slice([1, -2, 0]), data) .. image-sg:: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_004.png :alt: plot contourf 3d :srcset: /auto_examples/howto_plot/images/sphx_glr_plot_contourf_3d_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.630 seconds) .. _sphx_glr_download_auto_examples_howto_plot_plot_contourf_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_contourf_3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_contourf_3d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_contourf_3d.zip `