【问题标题】:How can I hide the shafts of matplotlib.quiver()如何隐藏 matplotlib.quiver() 的轴
【发布时间】:2019-03-16 21:24:30
【问题描述】:

我想隐藏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])

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    一种方法是设置箭头大小headaxislengthheadlength,使箭头完全覆盖轴。这里的长度与向量长度“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])
    

    【讨论】:

      猜你喜欢
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 2011-05-04
      • 1970-01-01
      相关资源
      最近更新 更多