我需要绘制一个断开的圆圈列表,这些圆圈是我为其他目的而创建的。
我试图完全按照中的示例进行操作http://toblerity.org/shapely/manual.html#cascading-unions显示(参见code)但只有当圆圈重叠并且整体相连时才有效(这不是我的情况)。正如你所看到的,通过替换行
polygons = [Point(i, 0).buffer(0.7) for i in range(5)]
with
polygons = [Point(i, 0).buffer(0.7) for i in (0,4)]
与 and 中断AssertionError
对于笛卡尔(或 matplotlib 失败)不是多边形的东西assert vertices.ndim == 2
如果有人注释掉笛卡尔断言作为测试)
查看文档matplotlib.path.Path似乎可以使用MOVETO来实现这个目标,但shapely似乎并不支持。它是否正确?我有什么解决方法?
以下代码有效:
from shapely.ops import cascaded_union
from shapely.geometry import Point
import random
from matplotlib.patches import Polygon
import pylab as pl
import numpy as np
circles = [Point(random.random(), random.random()).buffer(random.random() * 0.1)
for i in range(100)]
polygons = cascaded_union(circles)
fig, ax = pl.subplots(figsize=(8, 8))
for polygon in polygons:
mpl_poly = Polygon(np.array(polygon.exterior), facecolor="g", lw=0, alpha=0.4)
ax.add_patch(mpl_poly)
ax.relim()
ax.autoscale()
输出:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)