Clearing a Mesh or the Entire PlotΒΆ

This example demonstrates how to remove elements from a scene.

# sphinx_gallery_thumbnail_number = 3
import pyvista as pv
plotter = pv.Plotter()
actor = plotter.add_mesh(pv.Sphere())
plotter.remove_actor(actor)
plotter.show()
../../_images/sphx_glr_clear_001.png

Out:

[(1.0, 1.0, 1.0), (0.0, 0.0, 0.0), (0.0, 0.0, 1.0)]

Clearing the entire plotting window:

plotter = pv.Plotter()
plotter.add_mesh(pv.Sphere())
plotter.add_mesh(pv.Plane())
plotter.clear()  # clears all actors
plotter.show()
../../_images/sphx_glr_clear_002.png

Out:

[(1.0, 1.0, 1.0), (0.0, 0.0, 0.0), (0.0, 0.0, 1.0)]

Or you can give any actor a name when adding it and if an actor is added with that same name at a later time, it will replace the previous actor:

plotter = pv.Plotter()
plotter.add_mesh(pv.Sphere(), name="mydata")
plotter.add_mesh(pv.Plane(), name="mydata")
# Only the Plane is shown!
plotter.show()
../../_images/sphx_glr_clear_003.png

Out:

[(1.5773502691896262, 1.5773502691896262, 1.5773502691896262), (0.0, 0.0, 0.0), (0.0, 0.0, 1.0)]

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

Gallery generated by Sphinx-Gallery