3D散点图的2D投影Python

时间:2019-11-29 10:04:27

标签: python 3d data-visualization

我正在尝试可视化一个stl文件。我将numpy-stl与mplot3d结合使用。我将3d点作为散点图绘制时没有问题,但是我不能使用plot_surfac,输出错误是这样的:

 File "C:\Users\mgijon\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1614, in plot_surface
    if Z.ndim != 2:
AttributeError: 'list' object has no attribute 'ndim'

代码如下:

from matplotlib import pyplot
import numpy as np 
from stl import mesh
from mpl_toolkits import mplot3d 
from matplotlib import pyplot

your_mesh = mesh.Mesh.from_file('skull_ring.stl')

points = your_mesh.points
vectors = your_mesh.vectors

num_triangles, _ = points.shape

triangles = []

for triangle in range(num_triangles):
    triangles.append(points[triangle])

all_points = []

for triangle in triangles:
    all_points.append(triangle[:3])
    all_points.append(triangle[3:6])
    all_points.append(triangle[6:])

x = [point[0] for point in all_points]
y = [point[1] for point in all_points]
z = [point[2] for point in all_points]

fig = pyplot.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z, linewidth=0)
pyplot.show()

0 个答案:

没有答案