API Reference#

Background Plotter#

Attributes

ICON_TIME_STEP

staticMetaObject

window_size

Return render window size.

Methods

add_callback(func[, interval, count])

Add a function that can update the scene in the background.

add_editor()

Add the editor.

add_menu_bar()

Add the main menu bar.

add_toolbars()

Add the toolbars.

clear_camera_positions()

Clear all camera positions.

close()

Close the plotter.

reset_key_events()

Reset all of the key press events to their defaults.

save_camera_position()

Save camera position to saved camera menu for recall.

scale_axes_dialog([show])

Open scale axes dialog.

set_icon(img)

Set the icon image.

update_app_icon()

Update the app icon if the user is not trying to resize the window.

class pyvistaqt.BackgroundPlotter(show: bool = True, app: QApplication | None = None, window_size: Tuple[int, int] | None = None, off_screen: bool | None = None, allow_quit_keypress: bool = True, toolbar: bool = True, menu_bar: bool = True, editor: bool = True, update_app_icon: bool | None = None, app_window_class: Type[MainWindow] | None = None, **kwargs: Any)#

Bases: QtInteractor

Qt interactive plotter.

Background plotter for pyvista that allows you to maintain an interactive plotting window without blocking the main python thread.

Parameters:
  • show – Show the plotting window. If False, show this window by running show()

  • app (optional) – Creates a QApplication if left as None.

  • window_size – Window size in pixels. Defaults to [1024, 768]

  • off_screen – Renders off screen when True. Useful for automated screenshots or debug testing.

  • allow_quit_keypress – Allow user to exit by pressing "q".

  • toolbar (bool) – If True, display the default camera toolbar. Defaults to True.

  • menu_bar (bool) – If True, display the default main menu. Defaults to True.

  • editor (bool) – If True, display the VTK object editor. Defaults to True.

  • update_app_icon – If True, update_app_icon will be called automatically to update the Qt app icon based on the current rendering output. If None, the logo of PyVista will be used. If False, no icon will be set. Defaults to None.

  • title (str, optional) – Title of plotting window.

  • multi_samples (int, optional) – The number of multi-samples used to mitigate aliasing. 4 is a good default but 8 will have better results with a potential impact on performance.

  • line_smoothing (bool, optional) – If True, enable line smothing

  • point_smoothing (bool, optional) – If True, enable point smothing

  • polygon_smoothing (bool, optional) – If True, enable polygon smothing

  • auto_update (float, bool, optional) – Automatic update rate in seconds. Useful for automatically updating the render window when actors are change without being automatically Modified. If set to True, update rate will be 1 second.

  • app_window_class (None, class, optional) – A subclass of MainWindow to use when creating the app window.

Examples

>>> import pyvista as pv
>>> from pyvistaqt import BackgroundPlotter
>>> plotter = BackgroundPlotter()
>>> _ = plotter.add_mesh(pv.Sphere())
ICON_TIME_STEP = 5.0#
add_callback(func: Callable, interval: int = 1000, count: int | None = None) None#

Add a function that can update the scene in the background.

Parameters:
  • func – Function to be called with no arguments.

  • interval – Time interval between calls to func in milliseconds.

  • count – Number of times func will be called. If None, func will be called until the main window is closed.

add_editor() None#

Add the editor.

add_menu_bar() None#

Add the main menu bar.

add_toolbars() None#

Add the toolbars.

clear_camera_positions() None#

Clear all camera positions.

close() None#

Close the plotter.

This function closes the window which in turn will close the plotter through signal_close.

counters: List[Counter]#
default_camera_tool_bar: QToolBar#
editor: Editor | None#
main_menu: QMenuBar#
reset_key_events() None#

Reset all of the key press events to their defaults.

Handles closing configuration for q-key.

save_camera_position() None#

Save camera position to saved camera menu for recall.

saved_camera_positions: list | None#
saved_cameras_tool_bar: QToolBar#
scale_axes_dialog(show: bool = True) ScaleAxesDialog#

Open scale axes dialog.

set_icon(img: ndarray | str) None#

Set the icon image.

Parameters:

img (numpy.ndarray, shape (w, h, c) | str) – The image. Should be uint8 and square (w == h). Can have 3 or 4 color/alpha channels (c). Can also be a string path that QIcon can load.

Notes

Currently string paths can silently fail, so make sure your path is something that produces a valid QIcon(img).

staticMetaObject = PySide6.QtCore.QMetaObject("BackgroundPlotter" inherits "QtInteractor": )#
update_app_icon() None#

Update the app icon if the user is not trying to resize the window.

url: QUrl#
property window_size: Tuple[int, int]#

Return render window size.

MultiPlotter#

Attributes

Methods

close()

Close the multi plotter.

show()

Show the multi plotter.

class pyvistaqt.MultiPlotter(app: QApplication | None = None, nrows: int = 1, ncols: int = 1, show: bool = True, window_size: Tuple[int, int] | None = None, title: str | None = None, off_screen: bool | None = None, **kwargs: Any)#

Bases: object

Qt interactive plotter.

Multi plotter for pyvista that allows to maintain an interactive window with multiple plotters without blocking the main python thread.

Parameters:
  • app (optional) – Creates a QApplication if left as None.

  • nrows (int) – Number of rows. Defaults to 1.

  • ncols (int) – Number of columns. Defaults to 1.

  • show (bool) – Show the plotting window. If False, show this window by running show()

  • window_size (tuple, optional) – Window size in pixels. Defaults to [1024, 768]

  • off_screen (bool, optional) – Renders off screen when True. Useful for automated screenshots or debug testing.

Examples

>>> import pyvista as pv
>>> from pyvistaqt import MultiPlotter
>>> plotter = MultiPlotter()
>>> _ = plotter[0, 0].add_mesh(pv.Sphere())
close() None#

Close the multi plotter.

show() None#

Show the multi plotter.

QtInteractor#

Attributes

Methods

close()

Quit application.

disable()

Disable this renderer's camera from being interactive.

dragEnterEvent(event)

Event is called when something is dropped onto the vtk window.

dropEvent(event)

Event is called after dragEnterEvent.

enable()

Enable this renderer's camera to be interactive.

gesture_event(event)

Handle gesture events.

key_press_event(obj, event)

Call key_press_event using a signal.

link_views_across_plotters(other_plotter[, ...])

Link the views' cameras across two plotters.

render()

Override the render method to handle threading issues.

class pyvistaqt.QtInteractor(parent: MainWindow = None, title: str = None, off_screen: bool = None, multi_samples: int = None, line_smoothing: bool = False, point_smoothing: bool = False, polygon_smoothing: bool = False, auto_update: float | bool = 5.0, **kwargs: Any)#

Bases: QVTKRenderWindowInteractor, BasePlotter

Extend QVTKRenderWindowInteractor class.

This adds the methods available to pyvista.Plotter.

Parameters:
  • parent – Qt parent.

  • title – Title of plotting window.

  • multi_samples – The number of multi-samples used to mitigate aliasing. 4 is a good default but 8 will have better results with a potential impact on performance.

  • line_smoothing – If True, enable line smothing

  • point_smoothing – If True, enable point smothing

  • polygon_smoothing – If True, enable polygon smothing

  • auto_update – Number of updates per second. Useful for automatically updating the render window when actors are change without being automatically Modified.

close() None#

Quit application.

disable()#

Disable this renderer’s camera from being interactive.

dragEnterEvent(event: QDragEnterEvent) None#

Event is called when something is dropped onto the vtk window.

Only triggers event when event contains file paths that exist. User can drop anything in this window and we only want to allow files.

dropEvent(event: QEvent) None#

Event is called after dragEnterEvent.

enable()#

Enable this renderer’s camera to be interactive.

gesture_event(event: QGestureEvent) bool#

Handle gesture events.

key_press_event(obj: Any, event: Any) None#

Call key_press_event using a signal.

key_press_event_signal#

Link the views’ cameras across two plotters.

Parameters:
  • other_plotter (BackgroundPlotter) – The plotter whose views will be linked.

  • view (int) – Link the views in other_plotter to the this view index.

  • other_views (int | list of int) – Link these views from other_plotter to the reference view. The default is None, in which case all views from other_plotter will be linked to the reference view.

Note

For linking views belonging to a single plotter, please use pyvista’s Plotter.link_views method.

render() None#

Override the render method to handle threading issues.

render_signal#
staticMetaObject = PySide6.QtCore.QMetaObject("QtInteractor" inherits "QVTKRenderWindowInteractor": Methods:   #33 type=Signal, signature=render_signal()   #34 type=Signal, signature=key_press_event_signal(PyObject,QString), parameters=PyObject, QString )#
url: QUrl#

Class inheritance#

This module contains the QtInteractor and BackgroundPlotter.

Diagram#

BackgroundPlotter
+-- QtInteractor
    |-- QVTKRenderWindowInteractor
    |   +-- QWidget
    +-- BasePlotter

MainWindow
+-- QMainWindow

Implementation#

BackgroundPlotter.__init__(...)
|-- self.app_window = MainWindow()
|-- self.frame = QFrame(parent=self.app_window)
+-- QtInteractor.__init__(parent=self.frame)
    |-- QVTKRenderWindowInteractor.__init__(parent=parent)
    |   +-- QWidget.__init__(parent, flags)
    |-- BasePlotter.__init__(...)
    +-- self.ren_win = self.GetRenderWindow()

Because QVTKRenderWindowInteractor calls QWidget.__init__, this will actually trigger BasePlotter.__init__ to be called with no arguments. This cannot be solved (at least) because using super() because QVTKRenderWindowInteractor.__init__ does not use super(), and also it might not be fixable because Qt is doing something in QWidget which is probably entirely separate from the Python super() process. We fix this by internally by temporarily monkey-patching BasePlotter.__init__ with a no-op __init__.