{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Line Widget {#line_widget_example}\n\nThe line widget can be enabled and disabled by the\n`pyvista.Plotter.add_line_widget`{.interpreted-text role=\"func\"} and\n`pyvista.Plotter.clear_line_widgets`{.interpreted-text role=\"func\"}\nmethods respectively. Unfortunately, PyVista does not have any helper\nmethods to utilize this widget, so it is necessary to pass a custom\ncallback method.\n\nOne particularly fun example is to use the line widget to create a\nsource for the `pyvista.DataSetFilters.streamlines`{.interpreted-text\nrole=\"func\"} filter. Again note the use of the `name` argument in\n`add_mesh`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nimport pyvista as pv\nfrom pyvista import examples\n\npv.set_plot_theme('document')\n\nmesh = examples.download_kitchen()\nfurniture = examples.download_kitchen(split=True)\n\narr = np.linalg.norm(mesh['velocity'], axis=1)\nclim = [arr.min(), arr.max()]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "p = pv.Plotter()\np.add_mesh(furniture, name='furniture', color=True)\np.add_mesh(mesh.outline(), color='black')\np.add_axes()\n\n\ndef simulate(pointa, pointb):\n streamlines = mesh.streamlines(\n n_points=10,\n max_steps=100,\n pointa=pointa,\n pointb=pointb,\n integration_direction='forward',\n )\n p.add_mesh(streamlines, name='streamlines', line_width=5, render_lines_as_tubes=True, clim=clim)\n\n\np.add_line_widget(callback=simulate, use_vertices=True)\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 }