pyvista.Plotter.add_line_widget

pyvista.Plotter.add_line_widget#

Plotter.add_line_widget(
callback,
bounds=None,
factor=1.25,
resolution=100,
color=None,
use_vertices=False,
pass_widget=False,
interaction_event=45,
)[source]#

Add a line widget to the scene.

This is useless without a callback function. You can pass a callable function that takes a single argument, the PolyData line output from this widget, and performs a task with that line.

Parameters:
callbackcallable()

The method called every time the line is updated. This has two options: Take a single argument, the PolyData line (default) or if use_vertices=True, then it can take two arguments of the coordinates of the line’s end points.

boundstuple(float), optional

Length 6 tuple of the bounding box where the widget is placed.

factorfloat, optional

An inflation factor to expand on the bounds when placing.

resolutionint, optional

The number of points in the line created.

colorColorLike, optional

Either a string, rgb sequence, or hex color string.

use_verticesbool, optional

Changes the arguments of the callback method to take the end points of the line instead of a PolyData object.

pass_widgetbool, default: False

If True, the widget will be passed as the last argument of the callback.

interaction_eventvtk.vtkCommand.EventIds, optional

The VTK interaction event to use for triggering the callback.

Returns:
vtk.vtkLineWidget

Created line widget.

Examples

Shows an interactive line widget to move the sliced object like in add_mesh_slice function.

>>> import pyvista as pv
>>> from pyvista import examples
>>> import numpy as np
>>> model = examples.load_channels()
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(model, opacity=0.4)
>>> def move_center(pointa, pointb):
...     center = (np.array(pointa) + np.array(pointb)) / 2
...     normal = np.array(pointa) - np.array(pointb)
...     single_slc = model.slice(normal=normal, origin=center)
...
...     _ = pl.add_mesh(single_slc, name="slc")
...
>>> _ = pl.add_line_widget(callback=move_center, use_vertices=True)
>>> pl.show()
../../../_images/pyvista-Plotter-add_line_widget-1_00_00.png