代码之家  ›  专栏  ›  技术社区  ›  eqzx

如何隐藏matplotlib.quiver()的轴

  •  1
  • eqzx  · 技术社区  · 7 年前

    我想隐藏箭头的轴 matplotlib.pyplot.quiver() . 似乎没有参数完全删除轴,因为箭头大小与轴大小成比例。

    如何删除或隐藏轴,因此箭头是唯一可见的组件?

    import matplotlib.pyplot as plt
    u = v = 2
    plt.quiver(0, 0, u, v, angles='xy', scale_units='xy', scale=1)
    plt.axis([-u-1, u+1, v-1, v+1])
    

    snippet output

    1 回复  |  直到 7 年前
        1
  •  0
  •   eqzx    7 年前

    一种方法是设置箭头的大小 headaxislength headlength 使头部完全覆盖轴。这里的长度与“xy”(向量长度)成比例,所以我们必须缩放 1. / width (逆比例)按矢量长度, np.sqrt(u**2 + v**2)

    import matplotlib.pyplot as plt
    import numpy as np
    u = v = 2
    length = np.sqrt(u**2 + v**2)
    width=0.005
    hal = hl = 1. / width * length
    plt.quiver(0, 0, u, v, angles='xy', scale_units='xy', scale=1, 
               headwidth=hl,
               headaxislength=hal,
               headlength=hl,
               width=width)
    plt.axis([-2, u+1, -2, v+1])
    

    enter image description here