Matplotlib: How to draw circle with face color gradient

How can I draw circles with different color gradients that are in the center of the circle and low towards the borders?

I can draw, say, 3 circles with different facecolors using the following code -

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

ellipse1 = patches.Ellipse(xy=(0, 0), width=4, height=4, angle=30, color='r', alpha=0.4)
ellipse2 = patches.Ellipse(xy=(-2, -2), width=4, height=4, angle=30, color='g', alpha=0.4)
ellipse3 = patches.Ellipse(xy=(3, -2), width=4, height=4, angle=30, color='b', alpha=0.4)

fig, ax = plt.subplots() 
ax.set_xlim((-5, 5))
ax.set_ylim((-5, 5))

ax.add_patch(ellipse1)
ax.add_patch(ellipse2)
ax.add_patch(ellipse3)

plt.show()

      

So, I am getting the following output -

3 flat color bells

I want to paint the circles with red, green and blue color gradients that are high in the center and below at the borders.

Is there a minimal way to modify existing code?

+3


source to share





All Articles