Plot and fill 3D volumes in Python

前端 未结 1 1691
夕颜
夕颜 2021-01-17 04:34

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 val

相关标签:
1条回答
  • 2021-01-17 04:50

    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)
    

    0 讨论(0)
提交回复
热议问题