Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib quiver scale

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 http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html

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?

like image 255
Mibou Avatar asked May 06 '11 12:05

Mibou


1 Answers

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.

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
like image 173
Paul Avatar answered Sep 20 '22 19:09

Paul