按照@Trenton McKinney 的建议,我选择了一个矩形补丁
这是我使用它的勾股定理证明:
from matplotlib.patches import Polygon
# 3/4/5 is the smallest pythagorean triple
side_a_length = 3
side_b_length = 4
hypotenuse = 5
fig, ax = plt.subplots()
triangle1 = Polygon([(0,0), (0, side_a_length), (side_b_length, 0)], ec="black", fc=[0,0,0,0])
# Label the triangle lines at the midpoints with appropriate offsets.
offset = 8
label(ax, "a", (0, side_a_length / 2), (-offset, 0))
label(ax, "b", (side_b_length / 2, 0), (0, -2 * offset))
label(ax, "c", (side_b_length / 2, side_a_length / 2), (0, offset))
ax.add_patch(triangle1)
label(ax, "b", (0, (side_a_length +side_a_length + side_b_length) /2), (-offset, 0))
label(ax, "a", (side_a_length / 2, side_a_length + side_b_length), (0, offset))
label(ax, "c", (side_a_length / 2, (side_a_length +side_a_length + side_b_length) /2), (0, -2 * offset))
label(ax, "c", (side_b_length, (side_a_length + side_b_length) /2), (-1.5 * offset, 0))
# Add lines to form other triangles.
line_width = .8
ax.plot([0, 0], [side_a_length, side_a_length + side_b_length], color="black", lw=line_width)
ax.plot([0,side_a_length], [side_a_length + side_b_length, side_a_length + side_b_length], color="black", lw=line_width)
ax.plot([side_a_length, 0], [side_a_length + side_b_length, side_a_length], color="black", lw=line_width)
ax.plot([side_a_length, side_b_length], [side_a_length + side_b_length, 0], color="black", lw=line_width)
# Right Triangles
right1 = matplotlib.patches.Rectangle((0,0),0.25,0.4, fc=[0,0,0,0], ec="black", zorder=0, lw=.7)
ax.add_patch(right1)
right2 = matplotlib.patches.Rectangle((0,side_a_length + side_b_length),0.4,0.25, fc=[0,0,0,0], ec="black", zorder=0, lw=.7, angle=-90)
ax.add_patch(right2)
right3 = matplotlib.patches.Rectangle((0, side_a_length), 0.325, 0.325, fc=[0,0,0,0], ec="black", zorder=0, lw=.7, angle=-35)
ax.add_patch(right3)
plt.ylim(-1,8)
plt.xlim(-1,8)
plt.axis('off')
plt.show()