Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: rod holland <rhh@st...>  20040511 20:58:09

The following code ====================== from matplotlib.matlab import * x = arange(0,20,.2) y = arange(0,20,.2) X, Y = meshgrid(x,y) z=zeros((len(x),len(y)),'f') for i in enumerate(x): for j in enumerate(y): z[i[0]][j[0]]=10*sin(i[1]*j[1]) #or z[i[0],j[0]]=10*sin(i[1]*j[1]) pcolor(X,Y, transpose(z),shading='faceted') show() ======================= breaks in the module color.py ============================= def get_color(self, val, valmin, valmax): # map val to a range from 0 to 1 if iterable(val): s = "val must be a scalar. Perhaps you meant to call get_colors?" #print val,type(val) raise ValueError, s #print valmin, valmax #print val,type(val) ind = self.indmax*(valvalmin)/(valmaxvalmin) return self.rgbs[self._bound_ind(ind)] ============================== because the test for iterable fails since the element C[i,j] is type <array>. One solution is to change the code section around line 1126 in axes.py from c = C[i,j] to the following. ===================== for i in range(Nx1): for j in range(Ny1): c = C[i][j] ======================= the form C[i][j] seems to always return float. 
From: Perry Greenfield <perry@st...>  20040511 21:38:09

What you are seeing is one of the odd inconsistencies present in Numeric regarding what kind of thing is returned for a single element. This has been discussed on the numpy list some years back. >>> a = zeros((3,3), 'f') >>> type(a[0,0]) <type 'array'> >>> type(a[0][0]) <type 'float'> >>> b = zeros((3,3), 'd') >>> type(b[0,0]) <type 'float'> >>> type(b[0][0]) <type 'float'> So what kind of thing you get back when indexing a 2d array depends on both the type and dimensionality of the array. The basic rule is that if the array is more than one dimension, and not one of the basic python numerical types (e.g., 'f') then indexing a single element tries to preserve the type by returning a rank0 array of the same type. Oddly though, indexing a single element of a 1d 'f' array returns a Python float scalar (why the difference, I have no idea). This is why a[0][0] returns something different than a[0,0] since one is indexing a 1d array (a[0]). For numarray we decided that indexing a single element would always return a Python scalar since that seemed to be what most expected. There were those that argued that it should always return a rank0 array, but we decided against that. Perry > Original Message > From: matplotlibdeveladmin@... > [mailto:matplotlibdeveladmin@...]On Behalf Of rod > holland > Sent: Tuesday, May 11, 2004 4:59 PM > To: matplotlibdevel@... > Subject: [matplotlibdevel] problem with <type 'array'> in pcolor > > > The following code > > ====================== > from matplotlib.matlab import * > > x = arange(0,20,.2) > y = arange(0,20,.2) > X, Y = meshgrid(x,y) > z=zeros((len(x),len(y)),'f') > for i in enumerate(x): > for j in enumerate(y): > z[i[0]][j[0]]=10*sin(i[1]*j[1]) > #or z[i[0],j[0]]=10*sin(i[1]*j[1]) > pcolor(X,Y, transpose(z),shading='faceted') > show() > ======================= > > breaks in the module color.py > > ============================= > def get_color(self, val, valmin, valmax): > # map val to a range > from 0 to 1 > if iterable(val): > s = "val must be a scalar. > Perhaps you meant to call get_colors?" > #print val,type(val) > raise ValueError, s > #print valmin, valmax > #print > val,type(val) > ind = self.indmax*(valvalmin)/(valmaxvalmin) > return > self.rgbs[self._bound_ind(ind)] > ============================== > > because the test for iterable fails since the element C[i,j] is type > <array>. One solution is to change the code section around line 1126 in > axes.py from c = C[i,j] to the following. > > ===================== > for i in range(Nx1): > for j in range(Ny1): > > c = C[i][j] > ======================= > > > the form C[i][j] seems to always return float. > > > >  > This SF.Net email is sponsored by Sleepycat Software > Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to > deliver higher performing products faster, at low TCO. > http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3 > _______________________________________________ > Matplotlibdevel mailing list > Matplotlibdevel@... > https://lists.sourceforge.net/lists/listinfo/matplotlibdevel > 
Sign up for the SourceForge newsletter:
No, thanks