# Plot functions in dolfinx

**URL:** <https://fenicsproject.discourse.group/t/plot-functions-in-dolfinx/5452>\
**Category:** Uncategorized\
**Created:** [March 29, 2021, 1:17pm UTC](https://fenicsproject.discourse.group/t/plot-functions-in-dolfinx/5452 "2021-03-29T13:17:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [April 13, 2021, 1:37pm UTC](https://fenicsproject.discourse.group/t/plot-functions-in-dolfinx/5452/5 "2021-04-13T13:37:39Z")

</div>

I have not experienced that issue.  
Here is my minimal example (using ubuntu 20.04 locally), where both interactive or non-interactive plotting works using docker:

```bash
#On your own system:
xhost + 

docker run -ti -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/home/shared -w /home/shared --name=name_of_container --shm-size=512m dolfinx/dolfinx
# Inside docker container 
apt-get update
apt-get install -y --no-install-recommends libgl1-mesa-dev xvfb
pip3 install pyvista
# Change to True if you only want to save a png
echo 'export PYVISTA_OFF_SCREEN=False' >> ~/.bashrc
exec bash

# After exiting container
xhost -

# Next time you use the container
xhost + 
docker container start -i name_of_container

```

Minimal python code:

```python
import dolfinx
import dolfinx.plot
import numpy as np
from mpi4py import MPI

try:
    import pyvista
except ModuleNotFoundError:
    print("pyvista is required for this demo")
    exit(0)

if pyvista.OFF_SCREEN:
    pyvista.start_xvfb(wait=0.1)

N = 2
mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, N, N)

# Extract mesh data from dolfin-X (only plot cells owned by the
# processor) and create a pyvista UnstructuredGrid
num_cells = mesh.topology.index_map(mesh.topology.dim).size_local
cell_entities = np.arange(num_cells, dtype=np.int32)
pyvista_cells, cell_types = dolfinx.plot.create_vtk_topology(
    mesh, mesh.topology.dim, cell_entities)
grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, mesh.geometry.x)

plotter = pyvista.Plotter()
plotter.add_mesh(grid, style="wireframe", line_width=2, color="black")
plotter.view_xy()
# Save as png if we are using a container with no rendering
if pyvista.OFF_SCREEN:
    plotter.screenshot("tmp.png")
else:
    plotter.show()

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/plot-functions-in-dolfinx/5452)._
