import firedrake
import pyvista
import viskex
Generate a mesh of the unit square by dividing each edge of the square in 6 segments.
square = firedrake.UnitSquareMesh(6, 6, distribution_parameters={"partitioner_type": "simple"})
The interactive plots rendered in jupyter notebooks are prepared by trame
, which is integrated in pyvista
. The available backends are:
client
backend (interactive), which renders the scene on the client side using vtk.js
,server
backend (interactive), which runs a VTK render window on the server and sends back a compressed image,html
backend (partially interactive), which generates a static HTML representation of the scene,trame
backend (interactive or partially interactive), a default among client
, server
and html
,static
backend (not interactive), a static image of the scene.viskex
automatically chooses the default backend as follows:
VISKEX_PYVISTA_BACKEND
is provided, then the default client is its value; otherwisehtml
, as the other backends are not functional there; otherwiseclient
.The simplest way to set the plotting backend is by setting the variable VISKEX_PYVISTA_BACKEND
in the environment before running the notebook. The chosen backend will be used in every plot.
If a more fine grained control is needed (e.g., setting a different backend for each plot), users can change the backend in one of the following ways:
viskex.FiredrakePlotter
class instead of the viskex.firedrake
functions. The functions in the viskex.firedrake
module delegate the preparation of the pyvista
plotter to the viskex.FiredrakePlotter
class, and then automatically call .show()
on the prepared pyvista
plotter. Instead, by using the lower level class the jupyter_backend
can be passed as keyword argument to the pyvista
plotter. The choice of the backend will only be applied to the current plot.plotter_client = viskex.FiredrakePlotter.plot_mesh(square)
plotter_client.show(jupyter_backend="client")
plotter_html = viskex.FiredrakePlotter.plot_mesh(square)
plotter_html.show(jupyter_backend="html")
plotter_static = viskex.FiredrakePlotter.plot_mesh(square)
plotter_static.show(jupyter_backend="static")
jupyter_backend
in pyvista
's global theme. The typical suggested workflow however would be to simply use the VISKEX_PYVISTA_BACKEND
environment variable, which sets that same theme option.backup_jupyter_backend = pyvista.global_theme.jupyter_backend
pyvista.global_theme.jupyter_backend = "client"
viskex.firedrake.plot_mesh(square)
pyvista.global_theme.jupyter_backend = "html"
viskex.firedrake.plot_mesh(square)
pyvista.global_theme.jupyter_backend = "static"
viskex.firedrake.plot_mesh(square)
pyvista.global_theme.jupyter_backend = backup_jupyter_backend