使用Matplotlib颤抖来更改箭头的大小 [英] Change size of arrows using matplotlib quiver

查看:61
本文介绍了使用Matplotlib颤抖来更改箭头的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using quiver from matplotlib to plot a vectorial field. I would like to change the size of the thickness of each arrow depending on the number of data which produced a specific arrow of the vector field. Therefore what I am looking for is not a general scale transformation of the arrow size, but the way to customize the thickness of the arrow in quiver one-by-one. Is it possible? Can you help me?

推荐答案

plt.quiver linewidths 参数控制箭头的粗细.如果将其传递为一维值数组,则每个箭头的粗细都会不同.

The linewidths parameter to plt.quiver controls the thickness of the arrows. If you pass it a 1-dimensional array of values, each arrow gets a different thickness.

例如,

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

创建从 0 到 2 的线宽.

creates linewidths growing from 0 to 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()

收益

这篇关于使用Matplotlib颤抖来更改箭头的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆