Python 是否有方法从matplotlib曲面打印导出stl文件?

Python 是否有方法从matplotlib曲面打印导出stl文件?,python,matplotlib,surface,Python,Matplotlib,Surface,我正在分析小鼠胚胎中心脏发育区域的形状变化。为此,我研究了组织内细胞的空间坐标是如何随时间变化的 我正在使用函数matplotlib.plot\u trisurf获取这些单元格坐标之间的三角化曲面: 现在,我想计算这个三角化曲面的面积,并将曲面提取为.stl文件,以便在其他3D浏览器中使用,如MeshLab。我不知道怎么做 from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy a

我正在分析小鼠胚胎中心脏发育区域的形状变化。为此,我研究了组织内细胞的空间坐标是如何随时间变化的

我正在使用函数
matplotlib.plot\u trisurf
获取这些单元格坐标之间的三角化曲面:

现在,我想计算这个三角化曲面的面积,并将曲面提取为
.stl
文件,以便在其他3D浏览器中使用,如
MeshLab
。我不知道怎么做

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

##Data, spatial coordinates for each of the cells forming the tissue.

X = np.array([157.68627725, 103.11761198, 157.51873667, 165.81563644,
        77.9816598 , 126.77531671,  90.24263806, 162.27734804,
       122.62725478,  83.2503042 , 162.59702484,  88.3921336 ])

Y = np.array([-174.21831735, -144.38094418, -144.87819434, -181.84569162,
       -116.19711147, -133.53935007, -139.02422794, -141.49550572,
       -137.70714927, -144.36804192, -174.05904052, -120.61181162])

Z = np.array([-40.21972608,  19.97958051, -49.49361177, -69.6049367 ,
       -10.5853926 , -22.06279801,  23.51722221, -72.24126518,
         8.24172533,  42.0251029 , -49.31600354, -16.93026202])

##Plot triangulated surface

fig = plt.figure(figsize = (10, 4.5))
ax = fig.add_subplot(121, projection = '3d')

ax.plot_trisurf(X,Y,Z) 
我在找这样的东西:
我在谷歌上找到了这个解决方案,它对我有效。在我的例子中,我在绘图之前做了三角测量。在之前安装库numpy stl()。然后,尝试添加以下代码:

import stl
from stl import mesh
triang=triangulation(x,y,z)
data = np.zeros(len(triang.triangles), dtype=mesh.Mesh.dtype)
mobius_mesh = mesh.Mesh(data, remove_empty_areas=False)
mobius_mesh.x[:] = x[triang.triangles]
mobius_mesh.y[:] = y[triang.triangles]
mobius_mesh.z[:] = z[triang.triangles]
mobius_mesh.save('mysurface.stl')

这并不能回答您的问题,但您可以将xyz文件作为点云导入meshlab,它将自己对数据进行三角化。如果需要,也可以从meshlab导出.stl文件。谢谢Rafael!我会尝试一下,如果有效的话会告诉你
import stl
from stl import mesh
triang=triangulation(x,y,z)
data = np.zeros(len(triang.triangles), dtype=mesh.Mesh.dtype)
mobius_mesh = mesh.Mesh(data, remove_empty_areas=False)
mobius_mesh.x[:] = x[triang.triangles]
mobius_mesh.y[:] = y[triang.triangles]
mobius_mesh.z[:] = z[triang.triangles]
mobius_mesh.save('mysurface.stl')