Note
Go to the end to download the full example code
Slider Bar Widget#
The slider widget can be enabled and disabled by the
pyvista.Plotter.add_slider_widget()
and
pyvista.Plotter.clear_slider_widgets()
methods respectively.
This is one of the most versatile widgets as it can control a value that can
be used for just about anything.
One helper method we’ve added is the
pyvista.Plotter.add_mesh_threshold()
method which leverages the
slider widget to control a thresholding value.
import pyvista as pv
from pyvista import examples
mesh = examples.download_knee_full()
p = pv.Plotter()
p.add_mesh_threshold(mesh)
p.show()
![slider bar widget](https://d33wubrfki0l68.cloudfront.net/48fdc7b61bda389e1138d7663f4464b9cee122d1/98074/_images/sphx_glr_slider-bar-widget_001.png)
After interacting with the scene, the threshold mesh is available as:
[UnstructuredGrid (0x7f48bbc3a020)
N Cells: 295424
N Points: 394455
X Bounds: 3.615e+01, 1.178e+02
Y Bounds: 1.085e+01, 1.345e+02
Z Bounds: 0.000e+00, 2.000e+02
N Arrays: 1]
And here is a screen capture of a user interacting with this
![https://d33wubrfki0l68.cloudfront.net/491d9009ee2fa857b9deb4843b1e40bd106d01bc/606fd/_images/slider-widget-threshold.gif](https://d33wubrfki0l68.cloudfront.net/491d9009ee2fa857b9deb4843b1e40bd106d01bc/606fd/_images/slider-widget-threshold.gif)
Custom Callback#
Or you could leverage a custom callback function that takes a single value
from the slider as its argument to do something like control the resolution
of a mesh. Again note the use of the name
argument in add_mesh
:
p = pv.Plotter()
def create_mesh(value):
res = int(value)
sphere = pv.Sphere(phi_resolution=res, theta_resolution=res)
p.add_mesh(sphere, name='sphere', show_edges=True)
return
p.add_slider_widget(create_mesh, [5, 100], title='Resolution')
p.show()
![slider bar widget](https://d33wubrfki0l68.cloudfront.net/2bb12c467ae22dd16b622f0fa694261af0f63804/6db93/_images/sphx_glr_slider-bar-widget_002.png)
And here is a screen capture of a user interacting with this
![https://d33wubrfki0l68.cloudfront.net/2c3e20882f098d2ce1408fc62f058edad0dfdcdf/8e847/_images/slider-widget-resolution.gif](https://d33wubrfki0l68.cloudfront.net/2c3e20882f098d2ce1408fc62f058edad0dfdcdf/8e847/_images/slider-widget-resolution.gif)
Total running time of the script: (0 minutes 3.468 seconds)