gpt4 book ai didi

python - 使用 matplotlib quiver 改变箭头的大小

转载 作者:太空狗 更新时间:2023-10-30 02:04:59 27 4
gpt4 key购买 nike

我正在使用 matplotlib 中的 quiver 来绘制矢量场。我想要改变每个箭头粗细的大小取决于产生矢量场特定箭头的数据数量。所以我正在寻找的不是箭头大小的一般比例转换,而是方式逐个自定义箭袋中箭头的粗细。是否可以?你能帮帮我吗?

最佳答案

plt.quiverlinewidths 参数控制箭头的粗细。如果您向它传递一个一维值数组,则每个箭头都会有不同的粗细。

例如,

widths = np.linspace(0, 2, X.size)
plt.quiver(X, Y, cos(deg), sin(deg), linewidths=widths)

创建从 0 到 2 增长的线宽。


import matplotlib.pyplot as plt
import numpy as np
sin = np.sin
cos = np.cos

# http://stackoverflow.com/questions/6370742/#6372413
xmax = 4.0
xmin = -xmax
D = 20
ymax = 4.0
ymin = -ymax
x = np.linspace(xmin, xmax, D)
y = np.linspace(ymin, ymax, D)
X, Y = np.meshgrid(x, y)
# plots the vector field for Y'=Y**3-3*Y-X
deg = np.arctan(Y ** 3 - 3 * Y - X)
widths = np.linspace(0, 2, X.size)
plt.quiver(X, Y, cos(deg), sin(deg), linewidths=widths)
plt.show()

产量

enter image description here

关于python - 使用 matplotlib quiver 改变箭头的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701952/

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