Home > Software engineering >  Draw and Color Overlapping Circles with Shapely in Python
Draw and Color Overlapping Circles with Shapely in Python

Time:08-02

I am trying to draw and color overlapping circles using Shapely in Python. I've looked at several similar examples but keep running into problems with depreciated functions (like cascaded_union)

Here's my code so far:

import matplotlib.pyplot as plt
from shapely.geometry import Point, Polygon, MultiPoint, MultiPolygon



def plot_coords(coords):
    pts = list(coords)
    x, y = zip(*pts)
    plt.plot(x,y)


def plot_polys(polys):
    for poly in polys:
        plot_coords(poly.exterior.coords)

points = [Point(0, 0),
             Point(2,0),
             Point(1,2),
             Point(-1,2),
             Point(-2,0),
             Point(-1,-2),
             Point(1,-2)]

for point in points:
    plot_polys([point.buffer(2.2)])
    
plt.show()

The output looks like so:

enter image description here

From here, I would like to fill in the circles with colors I choose. I want the overlapping areas to have mixed colors, but to do this I need to figure out how to define the overlap. I tried following along enter image description here

  • Related