此代码绘制一个网格,然后在网格上绘制两个不同大小的圆。
from math import sqrt
# Calculate the center coordinates and add blue dots
for x in np.arange(0.5, 10, 1):
for y in np.arange(0.5, 10, 1):
plt.scatter(x, y, color='blue', s=10) # Adjust the size (s) as needed
# Draw a circle with center in the top left and radius to touch one of the blue dots
d = 3
circle1 = plt.Circle((0, 0), radius=sqrt(2) * (d + 0.5), color='red', alpha=0.5)
plt.gca().add_patch(circle1)
# Draw the second circle with a different radius
circle2 = plt.Circle((0, 0), radius=sqrt(2) * (d + 1 + 0.5), color='blue', alpha=0.5)
plt.gca().add_patch(circle2)
print(f"radius of smaller circle is {sqrt(2) * (d + 0.5)}")
print(f"radius of larger circle is {sqrt(2) * (d + 1 + 0.5)}")
# Draw a square at (4, 4) with a really thick edge
#square = patches.Rectangle((4, 4), 1, 1, fill=None, edgecolor='green', linewidth=5)
#plt.gca().add_patch(square)
plt.yticks(np.arange(0, 10.01, 1))
plt.xticks(np.arange(0, 10.01, 1))
plt.xlim(0,10)
plt.ylim(0,10)
# Manually set tick positions and labels
plt.gca().invert_yaxis()
# Set aspect ratio to be equal
plt.gca().set_aspect('equal', adjustable='box')
plt.grid()
这提供了:
我只想显示较大圆圈中的部分,而不是较小的部分。也就是说,蓝色的部分。我该怎么做?