Search code examples
pythonmatplotlibgeopandas

color half of the borders with GeoPandas


I have three polygons with common borders.

I can't figure out how to color only the inner half of the border.

For the moment I have:

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

So, I would like to color only the inner part of the border. This would allow for a two-color border between two polygons.


Solution

  • IIUC, you can apply a negative buffer before the 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