【问题标题】:Matplotlib arrows not in the right directionMatplotlib 箭头方向不对
【发布时间】:2022-10-25 23:21:46
【问题描述】:

我的箭头没有指向正确的方向。我不明白为什么法线或切线是错误的。这是代码。这个箭头应该与线平行。也许我已经失去了理智。

S1 = np.array([[-0.4,0.4],
            [-0.6,0.5]])

y1 = 0.5
y2 = 0.4
x1 = -0.6
x2 = -0.4
n1 = -(y2-y1)
n2 =  (x2-x1)
x, y = S1.T
plt.plot(x,y)
plt.quiver(-0.5, 0.45, (x2-x1), (y2-y1))
plt.show()

【问题讨论】:

    标签: matplotlib vector


    【解决方案1】:

    由于轴缩放,您没有得到预期的结果。请参阅matplotlib.axes.Axes.set_aspect 了解更多详情。使用plt.gca().set_aspect("equal") 将正确对齐箭头。

    例子:

    重现该图的代码:

    import numpy as np
    import matplotlib.pyplot as plt
    
    S1 = np.array([[-0.4,0.4],
                [-0.6,0.5]])
    
    y1 = 0.5
    y2 = 0.4
    x1 = -0.6
    x2 = -0.4
    n1 = (y2-y1)
    n2 =  (x2-x1)
    x, y = S1.T
    fig, ax = plt.subplots(nrows=1, ncols=2)
    
    ax[0].plot(x, y)
    ax[0].quiver(-0.5, 0.45, (x2-x1), (y2-y1))
    
    ax[1].plot(x, y)
    ax[1].quiver(-0.5, 0.45, (x2-x1), (y2-y1))
    ax[1].set_aspect("equal")
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 2016-02-17
      • 1970-01-01
      相关资源
      最近更新 更多