{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Slider Bar Widget {#slider_bar_widget_example}\n\nThe slider widget can be enabled and disabled by the\n`pyvista.Plotter.add_slider_widget`{.interpreted-text role=\"func\"} and\n`pyvista.Plotter.clear_slider_widgets`{.interpreted-text role=\"func\"}\nmethods respectively. This is one of the most versatile widgets as it\ncan control a value that can be used for just about anything.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One helper method we\\'ve added is the\n`pyvista.Plotter.add_mesh_threshold`{.interpreted-text role=\"func\"}\nmethod which leverages the slider widget to control a thresholding\nvalue.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples\n\nmesh = examples.download_knee_full()\n\np = pv.Plotter()\np.add_mesh_threshold(mesh)\np.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After interacting with the scene, the threshold mesh is available as:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "p.threshold_meshes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And here is a screen capture of a user interacting with this\n\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom Callback\n\nOr you could leverage a custom callback function that takes a single\nvalue from the slider as its argument to do something like control the\nresolution of a mesh. Again note the use of the `name` argument in\n`add_mesh`:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "p = pv.Plotter()\n\n\ndef create_mesh(value):\n res = int(value)\n sphere = pv.Sphere(phi_resolution=res, theta_resolution=res)\n p.add_mesh(sphere, name='sphere', show_edges=True)\n\n\np.add_slider_widget(create_mesh, [5, 100], title='Resolution')\np.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And here is a screen capture of a user interacting with this\n\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }