Debian Codegraph @

examples/02-plot/clear.py

raw
1 """
2 .. _clear_example:
3
4 Clearing a Mesh or the Entire Plot
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7 This example demonstrates how to remove elements from a scene using
8 :meth:`~pyvista.Plotter.clear`.
9
10 """
11
12 # sphinx_gallery_thumbnail_number = 3
13 import pyvista as pv
14
15 # %%
16
17 pl = pv.Plotter()
18 actor = pl.add_mesh(pv.Sphere())
19 pl.remove_actor(actor)
20 pl.show()
21
22
23 # %%
24 # Clearing the entire plotting window:
25
26 pl = pv.Plotter()
27 pl.add_mesh(pv.Sphere())
28 pl.add_mesh(pv.Plane())
29 pl.clear() # clears all actors
30 pl.show()
31
32
33 # %%
34 # Or you can give any actor a ``name`` when adding it and if an actor is added
35 # with that same name at a later time, it will replace the previous actor:
36
37 pl = pv.Plotter()
38 pl.add_mesh(pv.Sphere(), name='mymesh')
39 pl.add_mesh(pv.Plane(), name='mymesh')
40 # Only the Plane is shown.
41 pl.show()
42 # %%
43 # .. tags:: plot