从一个复杂的 3D 形状中,我通过 tricontourf 获得了我的形状的等效顶视图。
我现在希望将此结果导出到二维数组上。我试过这个:
import numpy as np
from shapely.geometry import Polygon
import skimage.draw as skdraw
import matplotlib.pyplot as plt
x = [...]
y = [...]
z = [...]
levels = [....]
cs = plt.tricontourf(x, y, triangles, z, levels=levels)
image = np.zeros((100,100))
for i in range(len(cs.collections)):
p = cs.collections[i].get_paths()[0]
v = p.vertices
x = v[:,0]
y = v[:,1]
z = cs.levels[i]
# to see polygon at level i
poly = Polygon([(i[0], i[1]) for i in zip(x,y)])
x1, y1 = poly.exterior.xy
plt.plot(x1,y1)
plt.show()
rr, cc = skdraw.polygon(x, y)
image[rr, cc] = z
plt.imshow(image)
plt.show()
但不幸的是,从轮廓顶点只创建一个多边形(我认为),最后在我的二维数组中生成我的轮廓的不正确投影。
您是否有想法在二维数组中正确表示轮廓?