我正在使用 matplotlib 中的 quiver 来绘制矢量场。我想要 改变每个箭头粗细的大小取决于 产生矢量场特定箭头的数据数量。所以 我正在寻找的不是箭头大小的一般比例转换,而是方式 逐个自定义箭袋中箭头的粗细。 是否可以?你能帮帮我吗?
最佳答案
plt.quiver
的linewidths
参数控制箭头的粗细。如果您向它传递一个一维值数组,则每个箭头都会有不同的粗细。
例如,
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()
产量
关于python - 使用 matplotlib quiver 改变箭头的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701952/