Reputation: 85
Is there a way to fill a circle created by :
ax.add_patch(ptc.Circle(.....)
with a vertical gradient from a colormap :
grad = cm.get_cmap('plasma', 100)
The expected output:
I don't know how to do this, but according to the picture someone got it with imshow ().
Thanks
Upvotes: 1
Views: 1814
Reputation: 80329
You can draw an image and set a clip path:
import numpy as np
import matplotlib.pyplot as plt
x, y, r = 0, 35, 25
fig, ax = plt.subplots()
img = ax.imshow(np.linspace(0, 1, 256).reshape(-1, 1), cmap='plasma',
extent=[x - r, x + r, y - r, y + r], origin='lower')
circle = plt.Circle((x, y), r, transform=ax.transData)
img.set_clip_path(circle)
ax.use_sticky_edges = False
ax.margins(x=0.05, y=0.05)
plt.show()
Upvotes: 4