Debian Codegraph @

examples/02-plot/ghost_cells.py

raw
1 """
2 .. _ghost_cells_example:
3
4 Hide Cells with Ghosting
5 ~~~~~~~~~~~~~~~~~~~~~~~~
6
7 Specify specific cells to hide when plotting.
8
9 This is a lightweight alternative to thresholding to quickly hide cells in a
10 mesh without creating a new mesh.
11
12 Notably, the mesh must be cast to an :class:`pyvista.UnstructuredGrid` type
13 for this to work (use the ``cast_to_unstructured_grid`` filter).
14 """
15
16 import numpy as np
17 from pyvista import examples
18
19 vol = examples.load_channels()
20 mesh = vol.cast_to_unstructured_grid()
21
22 # %%
23 # Decide which cells are ghosted with a criteria (feel free to adjust this
24 # or manually create this array to hide specific cells).
25 ghosts = np.argwhere(mesh['facies'] < 1.0)
26
27 # This will act on the mesh inplace to mark those cell indices as ghosts
28 mesh.remove_cells(ghosts, inplace=True)
29
30 # %%
31 # Now we can plot the mesh and those cells will be hidden
32 mesh.plot(clim=[0, 4])
33 # %%
34 # .. tags:: plot