用 geopandas 给一半边框上色

问题描述 投票:0回答:1

我有三个具有共同边界的多边形。 我不知道如何只为边框的内半部分着色。

目前我有:

data = [
        (gpd.read_file("shape1.shp"), "#f2a6a5"),
        (gpd.read_file("shape2.shp"), "#fbebc0"),
        (gpd.read_file("shape3.shp"), "#dacbab"),
    ]
    for poly, color in data:
        poly.boundary.plot(
            ax=ax,
            color=color,
            linestyle="solid",
            linewidth=6,
        )

enter image description here

所以,我只想对边框的内部部分进行着色。这将允许两个多边形之间有两种颜色的边框。

python matplotlib geopandas
1个回答
1
投票

IIUC,您可以在buffer

之前
应用否定
plot

D = -0.06 # to adjust

fig, ax = plt.subplots()

for poly, color in data:
    poly.buffer(D).boundary.plot( # <<< here
        ax=ax,
        color=color,
        linestyle="solid",
        linewidth=6,
    )

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.