## [matplotlib-devel] bug in vector plotting

 [matplotlib-devel] bug in vector plotting From: David Raymond - 2012-08-29 20:46:46 ```I think that I have found a serious bug in vector plotting (quiver) 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!) -- David J. Raymond Prof. of Physics New Mexico Tech http://www.physics.nmt.edu/~raymond/index.html ```

 [matplotlib-devel] bug in vector plotting From: David Raymond - 2012-08-29 20:46:46 ```I think that I have found a serious bug in vector plotting (quiver) 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!) -- David J. Raymond Prof. of Physics New Mexico Tech http://www.physics.nmt.edu/~raymond/index.html ```
 Re: [matplotlib-devel] bug in vector plotting From: Eric Firing - 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!) > ```
 Re: [matplotlib-devel] bug in vector plotting From: Eric Firing - 2012-08-29 23:22:06 ```On 2012/08/29 10:07 AM, David Raymond wrote: > > I think that I have found a serious bug in vector plotting (quiver) > 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. Not a bug. Note this in the documentation: *scale_units*: *None*, or any of the *units* options. For example, if *scale_units* is 'inches', *scale* is 2.0, and ``(u,v) = (1,0)``, then the vector will be 0.5 inches long. If *scale_units* is 'width', then the vector will be half the width of the axes. If *scale_units* is 'x' then the vector will be 0.5 x-axis units. To plot vectors in the x-y plane, with u and v having the same units as x and y, use "angles='xy', scale_units='xy', scale=1". Try this modified call to quiver: q = plt.quiver(X, Y, vx, vy, angles='xy', scale_units='xy') Eric ```