Debian Codegraph @

examples/02-plot/point_picking.py

raw
1 """
2 .. _point_picking_example:
3
4 Picking points on a mesh
5 ~~~~~~~~~~~~~~~~~~~~~~~~
6 This example demonstrates how to pick points on meshes using
7 :func:`enable_point_picking() <pyvista.Plotter.enable_point_picking>`.
8
9 """
10
11 # sphinx_gallery_thumbnail_number = 2
12 import pyvista as pv
13
14 # sphinx_gallery_start_ignore
15 # picking not work in interactive plots
16 PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True
17 # sphinx_gallery_end_ignore
18
19 # %%
20 # Pick points on a sphere
21 # +++++++++++++++++++++++
22 #
23 sphere = pv.Sphere()
24
25 pl = pv.Plotter()
26 pl.add_mesh(sphere, pickable=True)
27 pl.enable_point_picking()
28 pl.show()
29
30 # %%
31 # Ignore the 3D window
32 # ++++++++++++++++++++
33 #
34 # In the above example, both points on the mesh and points in the 3d window can be
35 # selected. It is possible instead pick only points on the mesh.
36 sphere = pv.Sphere()
37
38 pl = pv.Plotter()
39 pl.add_mesh(sphere, pickable=True)
40 pl.enable_point_picking(pickable_window=False) # Make the 3D window unpickable
41 pl.show()
42
43 # %%
44 # Modify which actors are pickable
45 # ++++++++++++++++++++++++++++++++
46 #
47 # After enabling point picking, we can modify which actors are pickable.
48 sphere = pv.Sphere()
49 cube = pv.Cube().translate([10, 10, 0])
50
51 pl = pv.Plotter()
52 sphere_actor = pl.add_mesh(sphere, pickable=True) # initially pickable
53 cube_actor = pl.add_mesh(cube, pickable=False) # initially unpickable
54 pl.enable_point_picking(pickable_window=False)
55
56 pl.pickable_actors = [sphere_actor, cube_actor] # now both are pickable
57 pl.view_xy()
58 pl.show()
59
60 # %%
61 # Pick using the left-mouse button
62 # ++++++++++++++++++++++++++++++++
63 #
64 sphere = pv.Sphere()
65
66 pl = pv.Plotter()
67 pl.add_mesh(sphere, pickable=True)
68 pl.enable_point_picking(left_clicking=True)
69 pl.show()
70 # %%
71 # .. tags:: plot