I'm trying to figure out how to color a Shapely polygon with a radial gradient. I start with some points and buffer them to circles. I used Grad from colorir to create a gradient of colors, but I want each circle to be a darker color at the center and fade to transparent at the edges. I looked at this post and am able to generate the image but I don't know how to apply it to my circles.
Here's my code so far:
import matplotlib.pyplot as plt
from shapely.geometry import Point, LineString
from colorir import Grad, PolarGrad
# functions for plotting
def plot_coords(coords, color):
pts = list(coords)
x, y = zip(*pts)
# print(color)
plt.plot(x,y, color="w", linewidth=.5)
plt.fill_between(x, y, facecolor=color, alpha = 0.4)
def plot_polys(polys, color):
for poly, color in zip(polys, color):
plot_coords(poly.exterior.coords, color)
x = 0
y = 0
h = 1.73205080757
# points
color_points = [
Point(x, y),
Point((x + 2), y),
Point((x - 2), y),
Point((x + 1), (y + h)),
Point((x - 1), (y + h)),
Point((x + 1), (y - h)),
Point((x - 1), (y - h))]
# buffer to circles
color_circles = []
for point in color_points:
color_circles.append(point.buffer(2))
# create gradient
p_grad = PolarGrad(["#2b70f3", "#f3ae2b"])
p_grad_colors = p_grad.n_colors(7)
fig = plt.figure()
ax = fig.add_subplot()
fig.subplots_adjust(top=0.85)
ax.set_aspect('equal')
plot_polys(color_circles, p_grad_colors)
plt.show()
My output looks like this:
But I would like each circle to look more like this:
Any help would be greatly appreciated!