.. 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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_plot_plot_contourf_3d.py: Visualizing 3D model data ========================= 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 14-23 .. code-block:: Python import numpy as np from pyvista import examples import ogstools as ot mesh = examples.load_channels() data = ot.variables.Scalar("facies", categoric=True, cmap="tab20") section = mesh.clip("y", (0, 20, 0)) .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: python ot.plot.contourf( section, data, show_edges=False, opacities={0: 0.2}, interactive=False ) .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: Python # only plotting a part of the example, as using opacities is expensive # performance-wise and the example is big. .. 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 .. GENERATED FROM PYTHON SOURCE LINES 42-46 It might make sense to plot multiple views / slices of 3D data. To create them we use the slicing functions of ``pyvista``. 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. .. GENERATED FROM PYTHON SOURCE LINES 48-49 Let's create multiple slices along the z axis and plot them in a 2 by 2 grid. .. GENERATED FROM PYTHON SOURCE LINES 49-55 .. code-block:: Python slices = np.reshape(list(mesh.slice_along_axis(n=4, axis="z")), (2, 2)) fig = ot.plot.contourf(slices, data, figsize=[8, 6], fontsize=12) 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 56-57 We can also slice along the y-axis and plot the meshes in one row. .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: Python slices = np.reshape(mesh.slice_along_axis(n=3, axis="y"), (1, -1)) fig = ot.plot.contourf(slices, data, figsize=[8, 6], fontsize=12) 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 64-66 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 66-69 .. code-block:: Python fig = ot.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 50.629 seconds) .. _sphx_glr_download_auto_examples_howto_plot_plot_contourf_3d.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_contourf_3d.py :alt: Launch binder :width: 150 px .. 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 `