.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/08_widgets/d_multi-slider-widget.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_08_widgets_d_multi-slider-widget.py: Multiple Slider Widgets ~~~~~~~~~~~~~~~~~~~~~~~ Use a class based callback to track multiple slider widgets for updating a single mesh. In this example we simply change a few parameters for the :func:`pyvista.Sphere` method, but this could easily be applied to any mesh-generating/altering code. .. GENERATED FROM PYTHON SOURCE LINES 13-38 .. code-block:: Python import pyvista as pv class MyCustomRoutine: def __init__(self, mesh): self.output = mesh # Expected PyVista mesh type # default parameters self.kwargs = { 'radius': 0.5, 'theta_resolution': 30, 'phi_resolution': 30, } def __call__(self, param, value): self.kwargs[param] = value self.update() def update(self): # This is where you call your simulation result = pv.Sphere(**self.kwargs) self.output.overwrite(result) return .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python starting_mesh = pv.Sphere() engine = MyCustomRoutine(starting_mesh) .. GENERATED FROM PYTHON SOURCE LINES 44-76 .. code-block:: Python p = pv.Plotter() p.add_mesh(starting_mesh, show_edges=True) p.add_slider_widget( callback=lambda value: engine('phi_resolution', int(value)), rng=[3, 60], value=30, title="Phi Resolution", pointa=(0.025, 0.1), pointb=(0.31, 0.1), style='modern', ) p.add_slider_widget( callback=lambda value: engine('theta_resolution', int(value)), rng=[3, 60], value=30, title="Theta Resolution", pointa=(0.35, 0.1), pointb=(0.64, 0.1), style='modern', ) p.add_slider_widget( callback=lambda value: engine('radius', value), rng=[0.1, 1.5], value=0.5, title="Radius", pointa=(0.67, 0.1), pointb=(0.98, 0.1), style='modern', ) p.show() .. image-sg:: /tutorial/08_widgets/images/sphx_glr_d_multi-slider-widget_001.png :alt: d multi slider widget :srcset: /tutorial/08_widgets/images/sphx_glr_d_multi-slider-widget_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/.virtualenvs/.venv/lib/python3.10/site-packages/pyvista/core/dataset.py:2123: PyVistaDeprecationWarning: Use of `DataSet.overwrite` is deprecated. Use `DataSet.copy_from` instead. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 77-80 And here is a screen capture of a user interacting with this .. image:: ../../images/gifs/multiple-slider-widget.gif .. GENERATED FROM PYTHON SOURCE LINES 82-89 .. raw:: html
Open In Colab
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.239 seconds) .. _sphx_glr_download_tutorial_08_widgets_d_multi-slider-widget.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/08_widgets/d_multi-slider-widget.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d_multi-slider-widget.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d_multi-slider-widget.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_