I have a VTK file (unstructured grid) with points and cells.
I can import the file and read it into using the meshio python package.
If I type the command mesh.cells I see a dictionary called 'hexahedron' with an array made up of lists inside like this:
{'hexahedron': array([[ 0, 162, 185, ..., 163, 186, 23],
[162, 329, 351, ..., 330, 352, 186],
[329, 491, 514, ..., 492, 515, 352],
...,
[483, 583, 600, ..., 584, 601, 490],
[583, 650, 656, ..., 651, 657, 601],
[650, 746, 762, ..., 747, 763, 657]])}
I would like to plot this in matplotlib (I know ParaView is an alternative, which I've been using, but I would also like to use matplotlib for this at the moment). Anyways, I'm having trouble wrapping my head around the structure.
There are 8 data points in each list.
If I run the command mesh.points I get an array of lists of x, y, z coordinates, which makes sense. However, with the hexahedron, are there also x, y, z coordinates in the list? It would make more sense if there were lists of x, y, z coordinates, as that would make up polygons.
I've seen this thread, but I'm still stuck on understanding this.
Attached is the VTK file, as well as what it looks like in ParaView. Thanks!
解决方案
tl;dr: I don't think you should try to use matplotlib for this, and it would be difficult and not work very well. I suggest using a dedicated vtk library, either bare vtk, the higher-level mayavi.mlab or my recently acquired favourite, pyvista. I'll elaborate on all this in detail.
The data
First, here is a small, self-contained version of your input data (since the data you linked in the question is both too large and likely to become a broken link sooner or later). I've reduced your data to three rectangular cuboids of varying sizes to approximate your figure.
# vtk DataFile Version 3.1
MCVE VTK file
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 16 float
0. 0. 0.
0. 0. 3.
0. 2. 0.
0. 2. 3.
4. 0. 0.
4. 0. 3.
4. 2. 0.
4. 2. 3.
5. 0. 0.
5. 0. 3.