[Matplotlib-users] NaN bugs

2008-07-25 Thread Ben Axelrod
I have noticed 2 bugs having to do with NaN handling in the scatter() function. 
 And one other bug that seems to be in numpy.

1. The min and max for the axes are not computed properly when there are NaNs 
in the data.  Example:

import pylab as pl
import numpy as np

x = np.asarray([0, 1, 2, 3, None, 5, 6, 7, 8, 9], float)
y = np.asarray([0, None, 2, 3, 4, 5, 6, 7, 8, 9], float)

ax = pl.subplot(111)
ax.scatter(x, y)
pl.show()

The points with NaN values are left out of the plot as expected, but you will 
see that everything before the NaN is ignored when computing the axis ranges.  
(The X axis goes from 4 to 10, cutting off some data, when it should be from -1 
to 10.  The Y axis goes from 1 to 10 when it should be also be from -1 to 10.)  
This is rather annoying since these simple calls fix the issue:

ax.set_xlim(min(x), max(y))
ax.set_ylim(min(y), max(y))


2.  We see the same behavior for the 'c' axis.  Example:

import pylab as pl
import numpy as np

x = np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], float)
y = np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], float)
z = np.asarray([0, 1, 2, 3, 4, 5, None, 7, 8, 9], float)

ax = pl.subplot(111)
ax.scatter(x, y, c=z)
pl.show()

We see that everything before point 7 has zero color.  And we can bandaid fix 
it by adding:

ax.scatter(x,  y, c=z,
   vmin=min(z),
   vmax=max(z))

Then only the one NaN point has zero color.


3.  Both of the above mentioned bandaid fixes suffer from some bug (I think in 
numpy).   Where the min() and max() of a numpy array where the first value is 
NaN, bugs out:

x = np.asarray([None, 1, 2, 3, 4, 5, 6, 7, 8, 9], float)
y = np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, None], float)
z = np.asarray([0, 1, 2, 3, 4, 5, None, 7, 8, 9], float)

print min(x), max(x)  #prints 1.#QNAN 1.#QNAN
print min(y), max(y)  #prints 0.0 8.0
print min(z), max(z)  #pritns 0.0 9.0


FYI, I am using MatPlotLib version 0.91.4 and NumPy 1.1.0 on windows and Debian 
Linux.

Thanks,
-Ben

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Help with converting from scilab

2008-07-25 Thread Peter Wesbdell
Hello all, my first post here.
 
I am moving from using scilab to Pylab, can anyone tell me why the two
following snippets of code produce very different results? BTW. The scilab
code produces the expected result.
 
Scilab:
Lx=1;
Ly=1;
n=2;
m=2;
f=100;
w=2*%pi*f;
t=1;
A=2;
Kx=n*%pi/Lx;
Ky=m*%pi/Ly;
x=linspace(0,100);
y=linspace(0,100);
z=zeros(100,100);
for i = 1:100
 for j = 1:100
  z(i,j) = A * sin(Kx*x(i)) * sin(Ky*y(j)) * %e^(%i*w*t);
end
end
contour(z)
 
 
Pylab:
from pylab import *
Lx=1
Ly=1
n=2
m=2
f=100
w=2*pi*f
t=1 
A=2
Kx=n*pi/Lx
Ky=m*pi/Ly
x=arange(0,100)
y=arange(0,100)
z=empty((100,100))
for i in range(1,100):
for j in range(1,100):
z[i, j] = A * sin(Kx*x[i]) * sin(Ky*y[j]) * e**(1j*w*t)
contourf(z)
show()
 
Cheers,
Pete.
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] NaN bugs

2008-07-25 Thread John Hunter
On Fri, Jul 25, 2008 at 10:08 AM, Ben Axelrod [EMAIL PROTECTED] wrote:
 I have noticed 2 bugs having to do with NaN handling in the scatter()

I believe this is fixed in svn (0.98 branch) -- I tested your first
example and it behaved as expected.  I f you have a build environment,
please test the release candidate

http://matplotlib.sourceforge.net/tmp/matplotlib-0.98.3rc1.tar.gz

Any other users who would like to test the release candidate, we would
be much obliged.  We do not have any binaries for testing
unfortunately.

JDH

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Help with converting from scilab

2008-07-25 Thread John Hunter
On Fri, Jul 25, 2008 at 10:22 AM, Peter Wesbdell
[EMAIL PROTECTED] wrote:
 Hello all, my first post here.

 I am moving from using scilab to Pylab, can anyone tell me why the two
 following snippets of code produce very different results? BTW. The scilab
 code produces the expected result.

I don't know what scilab does, but the filling of the z array looks
wrong, since python indexing starts at 0, not 1, so you would want to
do

for i in range(0,100):
for j in range(0,100):

but you rarely want to loop over arrays.  My snippet below shows how
to use meshgrid to use numpy's elementwise operations and avoid loops.
 By only filling starting at 1, you are using the memory in the 0-th
row and column unintialized (np.zeros can be safer than np.empty in
this regard) Also, be careful when defining constants as integers,
since integer division produces integers (3/2=1)

Here is my script - does it produce what you are expecting?


import numpy as np
import matplotlib.pyplot as plt

Lx = 1.
Ly = 1.
n = 2.
m = 2.
f = 100.
w = 2*np.pi*f
t = 1.
A = 2.
Kx = n*np.pi/Lx
Ky = m*np.pi/Ly
x = np.arange(100.)
y = np.arange(100.)
X, Y = np.meshgrid(x, y)
Z = A * np.sin(Kx*X) * np.sin(Ky*Y) * np.exp(1j*w*t)
plt.contourf(Z)
plt.show()




 Scilab:
 Lx=1;
 Ly=1;
 n=2;
 m=2;
 f=100;
 w=2*%pi*f;
 t=1;
 A=2;
 Kx=n*%pi/Lx;
 Ky=m*%pi/Ly;
 x=linspace(0,100);
 y=linspace(0,100);
 z=zeros(100,100);
 for i = 1:100
  for j = 1:100
   z(i,j) = A * sin(Kx*x(i)) * sin(Ky*y(j)) * %e^(%i*w*t);
 end
 end
 contour(z)


 Pylab:
 from pylab import *
 Lx=1
 Ly=1
 n=2
 m=2
 f=100
 w=2*pi*f
 t=1
 A=2
 Kx=n*pi/Lx
 Ky=m*pi/Ly
 x=arange(0,100)
 y=arange(0,100)
 z=empty((100,100))
 for i in range(1,100):
 for j in range(1,100):
 z[i, j] = A * sin(Kx*x[i]) * sin(Ky*y[j]) * e**(1j*w*t)
 contourf(z)
 show()

 Cheers,
 Pete.
 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
 Build the coolest Linux based applications with Moblin SDK  win great
 prizes
 Grand prize is a trip for two to an Open Source event anywhere in the world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Surf, mesh, and friends

2008-07-25 Thread David Arnold
All,

I am aware of the 3d examples at: http://scipy.org/Cookbook/ 
Matplotlib/mplot3D

However, this seems out of date, some examples work, some don't. Are  
there other pointers that show how I can use matplotlib to draw three  
dimensional surfaces similar to the ones drawn in Matlab with mesh,  
surf, and friends?

Any url's appreciated.

Thanks.

David

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] NaN bugs

2008-07-25 Thread Ryan May
Ben Axelrod wrote:
 3.  Both of the above mentioned bandaid fixes suffer from some bug (I 
 think in numpy).   Where the min() and max() of a numpy array where the 
 first value is NaN, bugs out:
 
  
 
 x = np.asarray([None, 1, 2, 3, 4, 5, 6, 7, 8, 9], float)
 
 y = np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, None], float)
 
 z = np.asarray([0, 1, 2, 3, 4, 5, None, 7, 8, 9], float)
 
  
 
 print min(x), max(x)  #prints 1.#QNAN 1.#QNAN
 
 print min(y), max(y)  #prints 0.0 8.0
 
 print min(z), max(z)  #pritns 0.0 9.0

It's actually pure luck that min/max worked at all.  What you want is 
numpy.nanmax() and numpy.nanmin() which properly handle NaN's in your array.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Surf, mesh, and friends

2008-07-25 Thread Ryan May
David Arnold wrote:
 All,
 
 I am aware of the 3d examples at: http://scipy.org/Cookbook/ 
 Matplotlib/mplot3D
 
 However, this seems out of date, some examples work, some don't. Are  
 there other pointers that show how I can use matplotlib to draw three  
 dimensional surfaces similar to the ones drawn in Matlab with mesh,  
 surf, and friends?

Unfortunately, the 3d plotting routine, axes3d, is unmaintained and 
unsupported.  It has actually been removed from SVN and won't be in 
future releases.  Volunteers are welcome to try and see if they can fix 
it. :)

Other options would be Vtk (with python bindings) (http://www.vtk.org) 
or Mayavi2 (https://svn.enthought.com/enthought/wiki/MayaVi).

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users