Hide Cells with Ghosting

Hide Cells with Ghosting#

Specify specific cells to hide when plotting.

This is a lightweight alternative to thresholding to quickly hide cells in a mesh without creating a new mesh.

Notably, the mesh must be cast to an pyvista.UnstructuredGrid type for this to work (use the cast_to_unstructured_grid filter).

from __future__ import annotations

import numpy as np

from pyvista import examples

vol = examples.load_channels()
mesh = vol.cast_to_unstructured_grid()

Decide which cells are ghosted with a criteria (feel free to adjust this or manually create this array to hide specific cells).

ghosts = np.argwhere(mesh['facies'] < 1.0)

# This will act on the mesh inplace to mark those cell indices as ghosts
mesh.remove_cells(ghosts, inplace=True)
HeaderData Arrays
UnstructuredGridInformation
N Cells1065589
N Points1336015
X Bounds0.000e+00, 2.500e+02
Y Bounds0.000e+00, 2.500e+02
Z Bounds0.000e+00, 1.000e+02
N Arrays2
NameFieldTypeN CompMinMax
faciesCellsint6411.000e+004.000e+00
vtkGhostTypeCellsuint810.000e+000.000e+00


Now we can plot the mesh and those cells will be hidden

mesh.plot(clim=[0, 4])
ghost cells

Tags: plot

Total running time of the script: (0 minutes 8.032 seconds)

Gallery generated by Sphinx-Gallery