Matplotlib 绘制比例三角形

Matplotlib draw proportional triangle

我画的三角形不平衡,怎么让它成比例?

    points = np.array([[x, 10], [x/2, 10], [x+1/2, np.sqrt(5**2 - 2**2)]])
    pivot = plt.Polygon(points, closed = True)
   

如果斜边长5,三角形高2,宽度的一半就是sqrt(5**2 + 2**2)。将左角放在 x,y 位置,右角将与 y 相同,宽度增加到 x。中心点将在 x 加上宽度的一半和 y+height:

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('dark_background')
slanted_side = 5
height = 2
halfwidth = np.sqrt(slanted_side ** 2 - height ** 2)
y = 10

fig, axes = plt.subplots()
# x = self.target_location
x = 3
pivot_left = (x, y)
pivot_right = (x + 2 * halfwidth, y)
pivot_top = (x + halfwidth, y + height)
points = np.array([pivot_left, pivot_right, pivot_top])
pivot = plt.Polygon(points, closed=True)
axes.add_patch(pivot)
axes.set_xlim(0, 20)
axes.set_ylim(0, 20)
axes.set_aspect('equal') # equal distances in x and y directions
plt.show()