From: <ef...@us...> - 2007-10-05 22:11:35
|
Revision: 3926 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3926&view=rev Author: efiring Date: 2007-10-05 15:11:32 -0700 (Fri, 05 Oct 2007) Log Message: ----------- Fixed numpification bug in pcolor argument handling Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2007-10-05 19:37:18 UTC (rev 3925) +++ trunk/matplotlib/lib/matplotlib/axes.py 2007-10-05 22:11:32 UTC (rev 3926) @@ -4408,7 +4408,30 @@ return im + def _pcolorargs(self, funcname, *args): + if len(args)==1: + C = args[0] + numRows, numCols = C.shape + X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) + elif len(args)==3: + X, Y, C = args + else: + raise TypeError( + 'Illegal arguments to %s; see help(%s)' % (funcname, funcname)) + Nx = X.shape[-1] + Ny = Y.shape[0] + if len(X.shape) <> 2 or X.shape[0] == 1: + x = X.reshape(1,Nx) + X = x.repeat(Ny, axis=0) + if len(Y.shape) <> 2 or Y.shape[1] == 1: + y = Y.reshape(Ny, 1) + Y = y.repeat(Nx, axis=1) + if X.shape != Y.shape: + raise TypeError( + 'Incompatible X, Y inputs to %s; see help(%s)' % (funcname, funcname)) + return X, Y, C + def pcolor(self, *args, **kwargs): """ pcolor(*args, **kwargs): pseudocolor plot of a 2-D array @@ -4520,25 +4543,9 @@ vmax = kwargs.pop('vmax', None) shading = kwargs.pop('shading', 'flat') - if len(args)==1: - C = args[0] - numRows, numCols = C.shape - X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) - elif len(args)==3: - X, Y, C = args - numRows, numCols = C.shape - else: - raise TypeError, 'Illegal arguments to pcolor; see help(pcolor)' + X, Y, C = self._pcolorargs('pcolor', *args) + Ny, Nx = X.shape - Nx = X.shape[-1] - Ny = Y.shape[0] - if len(X.shape) <> 2 or X.shape[0] == 1: - X = X.ravel().resize((Ny, Nx)) - if len(Y.shape) <> 2 or Y.shape[1] == 1: - Y = Y.ravel().resize((Nx, Ny)).T - - - # convert to MA, if necessary. C = ma.asarray(C) X = ma.asarray(X) @@ -4673,23 +4680,9 @@ shading = kwargs.pop('shading', 'flat') edgecolors = kwargs.pop('edgecolors', 'None') - if len(args)==1: - C = args[0] - numRows, numCols = C.shape - X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) - elif len(args)==3: - X, Y, C = args - numRows, numCols = C.shape - else: - raise TypeError, 'Illegal arguments to pcolormesh; see help(pcolormesh)' + X, Y, C = self._pcolorargs('pcolormesh', *args) + Ny, Nx = X.shape - Nx = X.shape[-1] - Ny = Y.shape[0] - if len(X.shape) <> 2 or X.shape[0] == 1: - X = X.ravel().resize((Ny, Nx)) - if len(Y.shape) <> 2 or Y.shape[1] == 1: - Y = Y.ravel().resize((Nx, Ny)).T - # convert to one dimensional arrays C = ma.ravel(C[0:Ny-1, 0:Nx-1]) # data point in each cell is value at lower left corner X = X.ravel() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |