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

标签 python matplotlib

我正在使用 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/

相关文章:

python - pandas CSV文件读取不会将数据类型从object转换为int

python - Google 距离矩阵 API 返回 'ZERO_RESULTS'

python - 运行时错误 :App registry isn't ready yet

python - 热图半球图

python - 绘制 matplotlib 错误栏给出 AssertionError 断言 vertices.ndim == 2

python - 对于形状为 (2,2) 的 numpy 数组,为什么 imshow 命令显示沿 x 和 y 轴的一系列值?这些值是什么?

python - pyplot step 函数不为第一个/最后一个点绘制水平

python - 解码和unicode之间的区别?

python - 从函数/类返回后如何使列表为空

python - 类型错误 : '>' not supported between instances of 'method' and 'int'