|
From: Eric F. <ef...@ha...> - 2012-08-29 23:01:35
|
On 2012/08/29 10:07 AM, David Raymond wrote:
>
> I think that I have found a serious bug in vector plotting (quiver)
I think you are correct, but a quick look at the code has not yet
revealed what is going wrong. I will look into it.
Eric
> when the "angle=xy" option is used on a plot with a large aspect
> ratio. It is my understanding that with this option, the vector with
> tail at (x,y) would have its head at (x + vx,y + vy); at least this is
> what it says in the documentation.
>
> The problem is best illustrated by the following example:
>
> ------------
>
> #!/usr/bin/python
> #
> from numpy import *
> import matplotlib.pyplot as plt
>
> lx = 100.
> ly = 10.
> pi = 3.14159
> kx = pi/lx
> ky = pi/ly
> nx = 21
> ny = 21
> x = linspace(0,lx,nx)
> y = linspace(0,ly,ny)
> (X,Y) = meshgrid(x,y)
>
> # this is a streamfunction
> psi = sin(kx*X)*sin(ky*Y)
>
> # these are the velocity components derived from the streamfunction
> vx = ky*sin(kx*X)*cos(ky*Y)
> vy = -kx*cos(kx*X)*sin(ky*Y)
>
> # plot the x velocity
> cx = plt.contourf(x,y,vx)
> b = plt.colorbar(cx, orientation='vertical')
> tl = plt.title("vx")
> xlab = plt.xlabel("x")
> ylab = plt.ylabel("y")
> plt.show()
>
> # plot the y velocity
> cy = plt.contourf(x,y,vy)
> b = plt.colorbar(cy, orientation='vertical')
> tl = plt.title("vy")
> xlab = plt.xlabel("x")
> ylab = plt.ylabel("y")
> plt.show()
>
> # plot the streamfunction and the velocity vectors using the angles=xy option
> cp = plt.contour(x,y,psi)
> q = plt.quiver(X,Y,vx,vy,angles='xy')
> tl = plt.title("psi contours, (vx,vy) vectors")
> xlab = plt.xlabel("x")
> ylab = plt.ylabel("y")
> plt.show()
>
> ------------------------------------
>
> The contour plot of vy, the y component of the vector, clearly shows
> that vy is non-zero at y = 5. However, the vector plot has it zero
> along this line. Interestingly, vx appears to be represented correctly
> on the x = 50 line. The magnitude of vectors should be inversely
> proportional to the spacing of streamfunction contours, and this is
> manifestly untrue in the vector plot.
>
> Please tell me if I am doing something stupid.
>
> Dave
>
> PS: I am using matplotlib 1.1.1 and numpy 1.6.2 on Arch linux. (Yes,
> I have to set the #!/bin/python line in the example to #!/bin/python2
> on Arch, since Arch has python3 as default!)
>
|