gpt4 book ai didi

python - 如何隐藏 matplotlib.quiver() 的轴

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:50 25 4
gpt4 key购买 nike

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

最佳答案

一种方法是设置箭头大小 headaxislengthheadlength,使头部完全覆盖轴。这里的长度与向量长度“xy”成正比,因此我们必须缩放1。/宽度(反比例)除以向量长度,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

关于python - 如何隐藏 matplotlib.quiver() 的轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55201631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com