Issue
I have the following code:
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import numpy as np
plt.yticks(np.arange(-10, 10.01, 1))
plt.xticks(np.arange(-10, 10.01, 1))
plt.xlim(-10,9)
plt.ylim(-10,9)
plt.gca().invert_yaxis()
# Set aspect ratio to be equal
plt.gca().set_aspect('equal', adjustable='box')
plt.grid()
np.random.seed(40)
square = np.empty((10, 10), dtype=np.int_)
for x in np.arange(0, 10, 1):
for y in np.arange(0, 10, 1):
plt.scatter(x, y, color='blue', s=2, zorder=2, clip_on=False)
for x in np.arange(0, 10, 1):
for y in np.arange(0, 10, 1):
value = np.random.randint(-3, 4)
square[int(x), int(y)] = value
r1 = 3
circle1 = Circle((0, 0), r1, color="blue", alpha=0.5, ec='k', lw=1)
r2 = 6
circle2 = Circle((0, 0), r2, color="blue", alpha=0.5, ec='k', lw=1)
plt.gca().add_patch(circle1)
plt.gca().add_patch(circle2)
This shows:
However I would like only the quarter of the circles that are over the x, y ranges 0 to 9 to be colored in and the rest to have a white background.
How can I do that?
Solution
IIUC, you need to replace circles with Wedge
s :
from matplotlib.patches import Wedge
r1 = 3
w1 = Wedge((0, 0), r1, 0, 90, color="blue", alpha=0.5, ec="k", lw=1)
r2 = 6
w2 = Wedge((0, 0), r2, 0, 90, color="blue", alpha=0.5, ec="k", lw=1)
plt.gca().add_patch(w1)
plt.gca().add_patch(w2)
Answered By - Timeless
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.