While these tutorials use jupyter notebooks, viskex
works out of the box also when running from a plain python file. Simply run python3 file.py
and a VTK render window will open for each plot.
There is also a way to emulate to force a VTK render window even from within a jupyter notebook.
import os
import dolfinx.mesh
import mpi4py.MPI
import pyvista
import viskex
Generate a mesh of the unit square by dividing each edge of the square in 6 segments.
square = dolfinx.mesh.create_unit_square(mpi4py.MPI.COMM_WORLD, 6, 6)
The simplest way to set the open a standalone VTK render window from within a jupyter notebook is by setting the variable VISKEX_PYVISTA_BACKEND
in the environment before running the notebook as export VISKEX_PYVISTA_BACKEND="none"
. The choice will be applied to every plot.
An equivalent setting is to change the pyvista
global theme option pyvista.global_theme.notebook
to False
.
backup_notebook = pyvista.global_theme.notebook
pyvista.global_theme.notebook = False
if os.environ.get("DISPLAY", "") != ":99": # do not open render window on CI or on website
viskex.dolfinx.plot_mesh(square)
pyvista.global_theme.notebook = backup_notebook