Introducing pyvista-xarray for 3D visualization

I’ve recently been working on pyvista-xarray to create a DataArray accessor that builds a direct line of interoperability between xarray and VTK/PyVista for 3D visualization.

This package is still in its early stages and I’d love to solicit as much feedback as possible from the xarray community about the types of data and ways in which you all would like to see this package improve to address 3D visualization needs.

Additionally, this package provides a DataSet IO backend for reading VTK files with xarray’s open_dataset function.

Please open an issue for any feedback you have or any new features you’d like to see!


Check out the README of the repository for examples, usage, and installation instructions: GitHub - pyvista/pyvista-xarray: PyVista DataArray accessors for xarray

import pvxarray
import rioxarray

da = rioxarray.open_rasterio("Elevation.tif")
da ="EPSG:3857")

# Grab the mesh object for use with PyVista
mesh = da.pyvista.mesh(x="x", y="y")

# Warp top and plot in 3D

Or open a VTK data file with xarray

import xarray as xr
import pyvista as pv

ds = xr.open_dataset("knee.vti", engine="pyvista")

# Generate PyVista mesh object
mesh = ds["SLCImage"].pyvista.mesh(x="x", y="y", z="z")

# Slice and plot

(would add screenshot but I’m too new of a user :frowning_face:)


@banesullivan , very cool! If you run this on a JupyterHub you need to have xvfb running, right?
So a JupyterHub users need to ask their JH admin to install xvfb in the container running JupyterLab, right?

1 Like

@rsignell, that is correct! Usually, this is as simple as having the following startup script:

set -x
sudo apt-get update && sudo apt-get install libgl1-mesa-glx xvfb -y
export DISPLAY=:99.0
which Xvfb
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
# give xvfb some time to start
sleep 3
set +x

We also have an OSMesa VTK wheel for PyVista to workaround xvfb/virtual frame buffers:

There is a Dockerfile in PyVista that demonstrates how to set this up: pyvista/jupyter.Dockerfile at main · pyvista/pyvista · GitHub

We usually have to apt install the following:

apt-get update \
 && apt-get install  -yq --no-install-recommends \
    libfontconfig1 \
    libxrender1 \

And then set the following ENV variable for PyVista for using ipyvtklink:


We should probably get this configuration into pangeo-docker-images.

1 Like