Most of the tooling you need is the UnstructuredGrid.extract_cells()
filter, which lets you select cells based on a boolean mask array or integer indices. Building such a mask is fairly easy if you compare the y
coordinates of cell centers with the specific value you are looking for:
import pyvista as pv
from pyvista.examples import download_puppy
# example data
mesh = download_puppy().threshold(80)
# example point coordinates: use middle cell's center
mesh_cell_centers = mesh.cell_centers()
x0, y0, z0 = mesh_cell_centers.points[mesh.n_cells // 2, :]
# plot example mesh
def plot_puppy():
"""Helper function to plot puppy twice."""
pl = pv.Plotter()
pl.background_color = 'lightblue'
pl.add_mesh(mesh, scalars='JPEGImage', rgb=True)
pl.add_bounding_box()
pl.camera.tight(padding=0.1)
return pl
plotter = plot_puppy()
plotter.show()
# extract cells with center y coordinate same as y0
indices_to_keep = mesh_cell_centers.points[:, 1] == y0 # boolean mask
# for inexact matching we could use np.isclose(mesh_cell_centers.points[:, 1], y0)
subset = mesh.extract_cells(indices_to_keep)
# visualize extracted cell centers with points
plotter = plot_puppy()
plotter.add_points(subset, color='red', render_points_as_spheres=True)
plotter.show()
The x0, y0, z0
in my example are the coordinates of the "middle" cell left after thresholding, in your actual use case you need something like y0 = mesh_cell_centers.points[:, 1].min()
if you want to match the cells with the lowest y
coordinate. In any case calling cell_centers()
is an important step to obtain the cell coordinates as points of an auxiliary mesh.
Here's what the thresholded puppy looks like:

The thresholding turns the original UniformGrid
image into an UnstructuredGrid
of scattered pixels. Starting from a UniformGrid
is also useful for matching y
coordinates exactly using ==
, but even without this we could use np.isclose
for approximate matching of float values (as I pointed out in a comment).
Here's the second image, where red spheres are superimposed on the puppy at positions that were matched in the mesh subset
(another UnstructuredGrid
):

This agrees with our expectations: we only see cells with a specific y
coordinate, and we only see cells where the puppy is not transparent.
Since you need the coordinates of the corresponding cells, you can just use subset.cell_centers().points
for an (n, 3)
-shaped array, or pick out the x
and z
coordinates with subset.cell_centers().points[:, [0, 2]]
with shape (n, 2)
.