Matplotlib 箭袋比例尺 [英] Matplotlib quiver scale

查看:63
本文介绍了Matplotlib 箭袋比例尺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有 quiver 函数的 matploblib 绘制一些箭头.但是我想使用数组分别选择每个箭头的长度.

I'm trying to plot some arrows using matploblib with the quiver function. But I want to choose the length of each arrow individually using an array.

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.quiver在这些演示和文档中,表明可以按单位(x,y,宽度,高度,xy,英寸,...)按比例更改比例,是否可以为每个箭头定义比例?

In these demos and documentation, it is show that you can change scales proportionally to units (x,y, width, height, xy, inches, ...), is there a way to define a scale for each arrow?

推荐答案

指定每个箭头的位置和向量长度是对箭袋图的过度规范.因此,您需要做的就是更改要绘制的数据.

To specify each arrow's location and vector and length is an over-specification of the quiver plot. So what you need to do is change the data that you are plotting.

如果您拥有向量字段U和V(与示例相同的U和V),则可以通过以下方式对其进行规范化:

If you have the vector field U and V (same U and V as your examples), you can normalize them by:

N = numpy.sqrt(U**2+V**2)  # there may be a faster numpy "normalize" function
U2, V2 = U/N, V/N

然后,您可以应用所需的任何比例因子数组:

Then you can apply whatever scaling factor array you want:

U2 *= F
V2 *= F

这篇关于Matplotlib 箭袋比例尺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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