Picking points on a mesh#

This example demonstrates how to pick points on meshes using enable_point_picking().

import pyvista as pv

Pick points on a sphere#

sphere = pv.Sphere()

p = pv.Plotter()
p.add_mesh(sphere, pickable=True)
p.enable_point_picking()
p.show()
point picking

Ignore the 3D window#

In the above example, both points on the mesh and points in the 3d window can be selected. It is possible instead pick only points on the mesh.

sphere = pv.Sphere()

p = pv.Plotter()
p.add_mesh(sphere, pickable=True)
p.enable_point_picking(pickable_window=False)  # Make the 3D window unpickable
p.show()
point picking

Modify which actors are pickable#

After enabling point picking, we can modify which actors are pickable.

sphere = pv.Sphere()
cube = pv.Cube()
cube.translate([10, 10, 0])

p = pv.Plotter()
sphere_actor = p.add_mesh(sphere, pickable=True)  # initially pickable
cube_actor = p.add_mesh(cube, pickable=False)  # initially unpickable
p.enable_point_picking(pickable_window=False)

p.pickable_actors = [sphere_actor, cube_actor]  # now both are pickable
p.view_xy()
p.show()
point picking
/home/runner/work/pyvista/pyvista/pyvista/core/pointset.py:206: PyVistaDeprecationWarning: You did not specify a value for `inplace` and the default value will be changing to `False` in future versions for point-based meshes (e.g., `PolyData`). Please make sure you are not assuming this to be an inplace operation.
  warnings.warn(DEFAULT_INPLACE_WARNING, PyVistaDeprecationWarning)

Pick using the left-mouse button#

sphere = pv.Sphere()

p = pv.Plotter()
p.add_mesh(sphere, pickable=True)
p.enable_point_picking(left_clicking=True)
p.show()
point picking

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

Gallery generated by Sphinx-Gallery