我正在尝试使用来自here的软件包Alphashape。
尽管我在初始页面中正确地复制并粘贴了示例,但还是出现了以下错误:
File "/anaconda3/lib/python3.8/site-packages/descartes/patch.py", line 87, in PolygonPatch
return PathPatch(PolygonPath(polygon), **kwargs)
File "/anaconda3/lib/python3.8/site-packages/descartes/patch.py", line 62, in PolygonPath
vertices = concatenate([
File "/anaconda3/lib/python3.8/site-packages/descartes/patch.py", line 63, in <listcomp>
concatenate([asarray(t.exterior)[:, :2]] +
IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed
我正在尝试的代码:
import numpy as np
from descartes import PolygonPatch
import matplotlib.pyplot as plt
import alphashape
points_2d = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
fig, ax = plt.subplots()
ax.scatter(*zip(*points_2d))
alpha_shape = alphashape.alphashape(points_2d, 0.)
ax.add_patch(PolygonPatch(alpha_shape, alpha=0.2))
plt.savefig(f"./test.png")
你知道为什么这行不通吗?
非常感谢!
1条答案
按热度按时间ezykj2lf1#
因此,据我所知,这个问题来自于笛卡尔对shapely的错误实现。
我的猜测是,shapely改变了它处理多边形外观的方式,笛卡尔根本没有更新。
我不知道这是否是最好的主意,但我直接编辑了我的笛卡尔安装来解决这个问题:
只需将t.exterior更改为t.exterior.coords,这有望解决您的问题。