【问题标题】:Plot and fill 3D volumes in Python在 Python 中绘制和填充 3D 体积
【发布时间】:2018-08-10 05:48:48
【问题描述】:

我正在使用 Python 处理一些 3D(体积)数据,对于每个四面体,我不仅有顶点的坐标,还有第四维,它是该四面体体积的某个参数的值。

例如:

# 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

我想绘制一个填充了一些纯色的 3D 体积(由节点坐标给出),这将代表给定值 C。

如何在 Python 3.6 中使用它的绘图库来做到这一点?

【问题讨论】:

    标签: python python-3.x numpy matplotlib scipy


    【解决方案1】:

    你可以使用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)
    

    【讨论】:

    • 谢谢!有没有其他图书馆为此目的?因为我遇到了一些问题installing Mayavi。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2021-03-20
    • 2021-05-14
    • 1970-01-01
    • 2015-01-12
    • 2021-06-04
    相关资源
    最近更新 更多