我正试着画一个被对角线截断的圆.以下是我的不起作用的代码:
import matplotlib.pyplot as plt
# Create the circle with radius 6
circle = plt.Circle((0, 0), 6, color='r', fill=False)
# Set up the plot (reuse the previous grid settings)
plt.figure(figsize=(8, 8))
plt.xlim(0, 10)
plt.ylim(0, 10)
plt.grid()
# Add the circle to the plot
ax = plt.gca()
ax.add_patch(circle)
# Draw a diagonal line
plt.plot([0, 7], [7, 0], color='b', linestyle='--')
# Set aspect ratio to ensure square grid cells
ax.set_aspect("equal")
# Clip the circle using the diagonal line.
# This doesn't work
ax.set_clip_path(plt.Polygon([[0, 0], [7, 0], [0, 7]]))
# Show the plot
plt.title("Circle Centered at (0,0) (not) Clipped by Diagonal Line")
plt.show()
以下是它目前显示的内容.
我不想显示任何超过对角线的圆.