IPython Tools

The IPython tools harness PyVista’s Qt rendering interface that enables accessible background plotting so that a rendering environment can be updated in real-time from a Jupyter notebook or other IPython environment.

These tools are useable from the top level of PyVista on any PyVista wrapped dataset. Simply call one of these tools on your object.

Attributes

loc

The location in the plotter window.

plotter

The active plotter that this tool uses.

renderer

Methods

tool()

This method is implemented for each tool to perfrom the data filtering and setting up the widgets

Orthogonal Slicer

The pyvista.OrthogonalSlicer tool on an example dataset to create three slices on the cartesian planes and move those slices through the dataset using slider bars directly in a Jupyter notebook:

import pyvista as pv
from pyvista import examples

dataset = examples.load_hexbeam()

# Use the slicer tool
pv.OrthogonalSlicer(dataset)
../_images/slicer-tool.gif
class pyvista.OrthogonalSlicer(dataset, plotter=None, scalars=None, preference='cell', show_bounds=False, reset_camera=True, outline=None, display_params=None, default_params=None, continuous_update=False, clean=True, **kwargs)

Bases: pyvista.plotting.ipy_tools.InteractiveTool

Within ipython enviornments like Jupyter notebooks, this will create an interactive render window with slider bars in te ipython enviornment to move orthogonal slices through the scene.

Parameters
  • dataset (pyvista.Common) – The datset to orthogonalally slice

  • plotter (pyvista.BasePlotter) – The active plotter (rendering window) to use

  • clean (bool, optional) – This will apply a threshold on the input dataset to remove any NaN values. Default is True if active scalar present.

  • step (float or tuple(float)) – The increments for the XYZ locations on each of the slider bars

  • scalars (str) – The name of the scalars to plot

  • preference (str, optional) – The preference for data choice when search for the scalar array

  • generate_triangles (bool, optional) – If this is enabled (False by default), the output will be triangles otherwise, the output will be the intersection polygons.

  • display_params (dict) – Any plotting keyword parameters to use

  • contour (bool, optional) – If True, apply a contour filter after slicing

Threshold

The pyvista.Threshold tool is used to interactively threshold a dataset using slider bars for the minimum and maximum range. This tool also has options to invert the threshold using checkboxes all directly in the output of a Jupyter notebook cell:

import pyvista as pv
from pyvista import examples

dataset = examples.load_uniform()

# Use the slicer tool
pv.Threshold(dataset)
../_images/threshold-tool.gif
class pyvista.Threshold(dataset, plotter=None, scalars=None, preference='cell', show_bounds=False, reset_camera=True, outline=None, display_params=None, default_params=None, continuous_update=False, clean=True, **kwargs)

Bases: pyvista.plotting.ipy_tools.InteractiveTool

Yields slider bars for user to control the threshold range in an interactive plot. The threshold will default at 25 and 75 percent of the range.

Parameters
  • dataset (pyvista.Common) – The datset to orthogonalally slice

  • plotter (pyvista.BasePlotter) – The active plotter (rendering window) to use

  • scalars (str) – The name of the scalars to plot

  • preference (str, optional) – The preference for data choice when search for the scalar array

  • display_params (dict) – Any plotting keyword parameters to use

Many Slices Along Axis

The pyvista.ManySlicesAlongAxis tool is used to create many (n) evenly spaced slices of a dataset along a specified axis. The user selects the number of slices via a slider bar and the axis to slice against via a drop down menu in the Jupyter notebook cell output:

import pyvista as pv
from pyvista import examples

dataset = examples.load_uniform()

# Use the many slices tool
pv.ManySlicesAlongAxis(dataset)
../_images/many-slices-tool.gif
class pyvista.ManySlicesAlongAxis(dataset, plotter=None, scalars=None, preference='cell', show_bounds=False, reset_camera=True, outline=None, display_params=None, default_params=None, continuous_update=False, clean=True, **kwargs)

Bases: pyvista.plotting.ipy_tools.InteractiveTool

Within ipython enviornments like Jupyter notebooks, this will create an interactive render window with slider bars in te ipython enviornment to create many slices along a specified axis.

Parameters
  • dataset (pyvista.Common) – The datset to orthogonalally slice

  • plotter (pyvista.BasePlotter) – The active plotter (rendering window) to use

  • clean (bool, optional) – This will apply a threshold on the input dataset to remove any NaN values. Default is True if active scalar present.

  • tolerance (float, optional) – The tolerance to the edge of the dataset bounds to create the slices

  • scalars (str) – The name of the scalars to plot

  • preference (str, optional) – The preference for data choice when search for the scalar array

  • generate_triangles (bool, optional) – If this is enabled (False by default), the output will be triangles otherwise, the output will be the intersection polygons.

  • display_params (dict) – Any plotting keyword parameters to use

  • contour (bool, optional) – If True, apply a contour filter after slicing

Isocontour

The pyvista.Isocontour tool creates a single value isocontour of a dataset along a point scalar array

import pyvista as pv
from pyvista import examples

dataset = examples.load_uniform()

# Use the contour tool
pv.Isocontour(dataset)
../_images/isocontour-tool.gif
class pyvista.ManySlicesAlongAxis(dataset, plotter=None, scalars=None, preference='cell', show_bounds=False, reset_camera=True, outline=None, display_params=None, default_params=None, continuous_update=False, clean=True, **kwargs)

Bases: pyvista.plotting.ipy_tools.InteractiveTool

Within ipython enviornments like Jupyter notebooks, this will create an interactive render window with slider bars in te ipython enviornment to create many slices along a specified axis.

Parameters
  • dataset (pyvista.Common) – The datset to orthogonalally slice

  • plotter (pyvista.BasePlotter) – The active plotter (rendering window) to use

  • clean (bool, optional) – This will apply a threshold on the input dataset to remove any NaN values. Default is True if active scalar present.

  • tolerance (float, optional) – The tolerance to the edge of the dataset bounds to create the slices

  • scalars (str) – The name of the scalars to plot

  • preference (str, optional) – The preference for data choice when search for the scalar array

  • generate_triangles (bool, optional) – If this is enabled (False by default), the output will be triangles otherwise, the output will be the intersection polygons.

  • display_params (dict) – Any plotting keyword parameters to use

  • contour (bool, optional) – If True, apply a contour filter after slicing

Using the Tools in an Integrated Scene

Each of the tools in this module can be used to either create a scene that can have other datasets added or the tools can be used on an already existing rendering scene. We commonly use the tools to apply a filter on a dataset while viewing it adjacent to other dataset.

The easiest approach is to use a tool to activate a new rendering window like performed in the above examples. This time be sure to assign the tool object so that you can access it’s plotting window:

import pyvista as pv
from pyvista import examples

dataset = examples.load_uniform()

# assign the tool to a variable
thresher = pv.Threshold(dataset)

Now a rendering environment will appear and the cell will output to IPython tools. Since the tool is captured in the variable thresher for this example, you can access the plotting window and add features or datasets:

# Grab the plotter
p = thresher.plotter

# Label the axes bounds
p.show_grid()

# Add some other datasets
p.add_mesh(dataset.clip())

You can also add as many tools to one rendering environment as you’d like by passing the plotter to the tool upon construction:

# Add a second tool by passing the plotter
slicer = pv.OrthogonalSlicer(dataset, plotter=p)

And now you have two tools being used in one rendering window!

../_images/integrated-tools.gif