pyvista.Plotter.show#

Plotter.show(
title=None,
window_size=None,
interactive=True,
auto_close=None,
interactive_update=False,
full_screen=None,
screenshot=False,
return_img=False,
cpos=None,
jupyter_backend=None,
return_viewer=False,
return_cpos=None,
before_close_callback=None,
**kwargs,
)[source]#

Display the plotting window.

Parameters:
titlestr, optional

Title of plotting window. Defaults to pyvista.global_theme.title.

window_sizelist, optional

Window size in pixels. Defaults to pyvista.global_theme.window_size.

interactivebool, optional

Enabled by default. Allows user to pan and move figure. Defaults to pyvista.global_theme.interactive.

auto_closebool, optional

Exits plotting session when user closes the window when interactive is True. Defaults to pyvista.global_theme.auto_close.

interactive_updatebool, default: False

Allows user to non-blocking draw, user should call Plotter.update() in each iteration.

full_screenbool, optional

Opens window in full screen. When enabled, ignores window_size. Defaults to pyvista.global_theme.full_screen.

screenshotstr | Path | io.BytesIO | bool, default: False

Take a screenshot of the initial state of the plot. If a string, it specifies the path to which the screenshot is saved. If True, the screenshot is returned as an array. For interactive screenshots it’s recommended to first call show() with auto_close=False to set the scene, then save the screenshot in a separate call to show() or Plotter.screenshot(). See also the before_close_callback parameter for an alternative.

return_imgbool, default: False

Returns a numpy array representing the last image along with the camera position.

cpossequence[sequence[float]], optional

The camera position. You can also set this with Plotter.camera_position.

jupyter_backendstr, optional

Jupyter notebook plotting backend to use. One of the following:

  • 'none' : Do not display in the notebook.

  • 'static' : Display a static figure.

  • 'trame' : Display a dynamic figure with Trame.

  • 'html' : Use an ebeddable HTML scene.

This can also be set globally with pyvista.set_jupyter_backend().

A dictionary jupyter_kwargs can also be passed to further configure how the backend displays.

return_viewerbool, default: False

Return the jupyterlab viewer, scene, or display object when plotting with Jupyter notebook. When False and within a Jupyter environment, the scene will be immediately shown within the notebook. Set this to True to return the scene instead.

return_cposbool, optional

Return the last camera position from the render window when enabled. Default based on theme setting. See pyvista.plotting.themes.Theme.return_cpos.

before_close_callbackCallable, optional

Callback that is called before the plotter is closed. The function takes a single parameter, which is the plotter object before it closes. An example of use is to capture a screenshot after interaction:

def fun(plotter):
    plotter.screenshot('file.png')
**kwargsdict, optional

Developer keyword arguments.

Returns:
cposlist

List of camera position, focal point, and view up. Returned only when return_cpos=True or set in the default global or plot theme.

imagenp.ndarray

Numpy array of the last image when either return_img=True or screenshot=True is set. Optionally contains alpha values. Sized:

  • [Window height x Window width x 3] if the theme sets transparent_background=False.

  • [Window height x Window width x 4] if the theme sets transparent_background=True.

widgetipywidgets.Widget

IPython widget when return_viewer=True.

Notes

Please use the q-key to close the plotter as some operating systems (namely Windows) will experience issues saving a screenshot if the exit button in the GUI is pressed.

Examples

Simply show the plot of a mesh.

>>> import pyvista as pv
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(pv.Cube())
>>> pl.show()
../../../_images/pyvista-Plotter-show-1_00_00.png

Take a screenshot interactively. Screenshot will be of the first image shown, so use the first call with auto_close=False to set the scene before taking the screenshot.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(pv.Cube())
>>> pl.show(auto_close=False)  
>>> pl.show(screenshot='my_image.png')  

Obtain the camera position when using show.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(pv.Sphere())
>>> pl.show(return_cpos=True)  
[(2.223005211686484, -0.3126909484828709, 2.4686209867735065),
(0.0, 0.0, 0.0),
(-0.6839951597283509, -0.47207319712073137, 0.5561452310578585)]