On this page


Download this notebook from GitHub (right-click to download).

import panel as pn
import pyvista as pv
from pyvista import examples
pn.extension('vtk', sizing_mode="stretch_width")

For this example we use the pyvista library to load a dataset and generate easily a VTK scene

m = examples.download_st_helens().warp_by_scalar()

# default camera position
cpos = [(567000.9232163235, 5119147.423216323, 6460.423216322832),
 (562835.0, 5114981.5, 2294.5),
 (-0.4082482904638299, -0.40824829046381844, 0.8164965809277649)]

# pyvista plotter
pl = pv.Plotter(notebook=True);
actor = pl.add_mesh(m, smooth_shading=True, lighting=True)
pl.camera_position = cpos #set camera position

# save initial camera properties
renderer = list(pl.ren_win.GetRenderers())[0]
initial_camera = renderer.GetActiveCamera()
initial_camera_pos = {"focalPoint": initial_camera.GetFocalPoint(),
                      "position": initial_camera.GetPosition(),
                      "viewUp": initial_camera.GetViewUp()}

# Panel creation using the VTK Scene created by the plotter pyvista
orientation_widget = True
enable_keybindings = True
vtkpan = pn.panel(pl.ren_win, sizing_mode='stretch_both', orientation_widget=orientation_widget,
                  enable_keybindings=enable_keybindings, height=600)