0

I am working with some 3D (volumetric) data using Python, and for every tetrahedron, I have not only the vertices's coordinates but also a fourth dimension which is the value of some parameter for that tetrahedron volume.

For example:

# nodes coordinates that defines a tetrahedron volume:
x = [0.0, 1.0, 0.0, 0.0]
y = [0.0, 0.0, 1.0, 0.0]
z = [0.0, 0.0, 0.0, 1.0]
# Scaler value of the potential for the given volume:
c = 100.0

I would like to plot a 3D volume (given by the nodes coordinates) filled with some solid color, which would represent the given value C.

How could I do that in Python 3.6 using its plotting libraries?

Gabs
  • 292
  • 5
  • 23

1 Answers1

1

You can use mayavi.mlab.triangular_mesh():

from mayavi import mlab

from itertools import combinations, chain

x = [0.0, 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 0.0]
y = [0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0]
z = [0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 3.0]
c = [20, 30]

triangles = list(chain.from_iterable(combinations(range(s, s+4), 3) for s in range(0, len(x), 4)))
c = np.repeat(c, 4)

mlab.triangular_mesh(x, y, z, triangles, scalars=c)

enter image description here

HYRY
  • 94,853
  • 25
  • 187
  • 187
  • Thank you! Is there any other library for that purpose? Because I've been having some issues [installing Mayavi](https://stackoverflow.com/questions/46597013/mayavi-install-on-python-3-6). – Gabs Mar 02 '18 at 02:57