# Plotting Partial Meshes

**URL:** <https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181>\
**Category:** mesh\
**Created:** [August 31, 2022, 9:46pm UTC](https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181 "2022-08-31T21:46:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![micBenn](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/micbenn/32/8296_2.png) [@micBenn](https://fenicsproject.discourse.group/u/micBenn)\
**Post date:** [August 31, 2022, 9:46pm UTC](https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181/1 "2022-08-31T21:46:26Z")

</div>

For problems with multiple subdomains, is it possible to plot solutions only over particular subdomains? In particular, I am working on a problem where there is a “background” mesh with objects inside of it, and I only care about the deformation of the objects. Would there be ways to plot the deformed state of particular subdomains (objects) without plotting others (background)?

I am currently plotting things in-line using pyvista as shown in the Hyperelasticity example but would like to eventually work with something external so that I can create animations of the time-varying solutions.

Any help would be greatly appreciated!

---

<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:** [September 2, 2022, 3:06pm UTC](https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181/2 "2022-09-02T15:06:45Z")

</div>

Are you using DOLFINx or DOLFIN?

---

<div class="post-metadata">

**Author:** ![micBenn](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/micbenn/32/8296_2.png) [@micBenn](https://fenicsproject.discourse.group/u/micBenn)\
**Post date:** [September 2, 2022, 3:19pm UTC](https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181/3 "2022-09-02T15:19:09Z")

</div>

Sorry for not including that. I am working with DOLFINx in the Jupyter lab environment.

---

<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:** [September 5, 2022, 7:22am UTC](https://fenicsproject.discourse.group/t/plotting-partial-meshes/9181/4 "2022-09-05T07:22:07Z")

</div>

You can map data from a bigger mesh to a smaller mesh, using the submeshes:

```python
import dolfinx
from mpi4py import MPI
import numpy as np
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
cells = np.array([6,8,12], dtype=np.int32)
V = dolfinx.fem.FunctionSpace(mesh, ("DG", 2))
u = dolfinx.fem.Function(V)
u.interpolate(lambda x: x[0],cells=np.arange(12, dtype=np.int32))

sub_mesh = dolfinx.mesh.create_submesh(mesh, mesh.topology.dim, cells)
V_sub = dolfinx.fem.FunctionSpace(sub_mesh[0], ("DG", 2))
v = dolfinx.fem.Function(V_sub)
for i, c in enumerate(cells):
    parent_dofs = V.dofmap.cell_dofs(c)
    sub_dofs = V_sub.dofmap.cell_dofs(i)
    assert V.dofmap.bs == V_sub.dofmap.bs
    for dof, sub_dof in zip(parent_dofs, sub_dofs):
        for j in range(V.dofmap.bs):
            v.x.array[sub_dof*V.dofmap.bs + j] = u.x.array[dof*V.dofmap.bs + j]

with dolfinx.io.VTXWriter(mesh.comm, "u.bp", u) as vtx:
    vtx.write(0.0)
with dolfinx.io.VTXWriter(mesh.comm, "v.bp", v) as vtx:
    vtx.write(0.0)

```

> [@micBenn](#):
>
> I am currently plotting things in-line using pyvista as shown in the Hyperelasticity example but would like to eventually work with something external so that I can create animations of the time-varying solutions.

You can use pyvista to create gifs, as for instance shown in:

> **[Solving a time-dependent problem — FEniCS 22 tutorial](https://jsdokken.com/fenics22-tutorial/heat_eq.html)**
