Revision: 7617 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7617&view=rev Author: ryanmay Date: 2009-08-31 17:29:41 +0000 (Mon, 31 Aug 2009)
Log Message: ----------- Pull _parse_args out of Quiver and Barbs classes, as we have multiple, diverging copies of the same code. Now the shared code will actually be shared. Modified Paths: -------------- branches/v0_99_maint/lib/matplotlib/quiver.py Modified: branches/v0_99_maint/lib/matplotlib/quiver.py =================================================================== --- branches/v0_99_maint/lib/matplotlib/quiver.py 2009-08-31 17:27:12 UTC (rev 7616) +++ branches/v0_99_maint/lib/matplotlib/quiver.py 2009-08-31 17:29:41 UTC (rev 7617) @@ -323,7 +323,30 @@ quiverkey_doc = _quiverkey_doc +# This is a helper function that parses out the various combination of +# arguments for doing colored vector plots. Pulling it out here +# allows both Quiver and Barbs to use it +def _parse_args(*args): + X, Y, U, V, C = [None]*5 + args = list(args) + if len(args) == 3 or len(args) == 5: + C = np.asanyarray(args.pop(-1)) + V = np.asanyarray(args.pop(-1)) + U = np.asanyarray(args.pop(-1)) + if U.ndim == 1: + nr, nc = 1, U.shape[0] + else: + nr, nc = U.shape + if len(args) == 2: # remaining after removing U,V,C + X, Y = [np.array(a).ravel() for a in args] + if len(X) == nc and len(Y) == nr: + X, Y = [a.ravel() for a in np.meshgrid(X, Y)] + else: + indexgrid = np.meshgrid(np.arange(nc), np.arange(nr)) + X, Y = [np.ravel(a) for a in indexgrid] + return X, Y, U, V, C + class Quiver(collections.PolyCollection): """ Specialized PolyCollection for arrows. @@ -343,7 +366,7 @@ """ def __init__(self, ax, *args, **kw): self.ax = ax - X, Y, U, V, C = self._parse_args(*args) + X, Y, U, V, C = _parse_args(*args) self.X = X self.Y = Y self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis])) @@ -388,26 +411,6 @@ by the following pylab interface documentation: %s""" % _quiver_doc - def _parse_args(self, *args): - X, Y, U, V, C = [None]*5 - args = list(args) - if len(args) == 3 or len(args) == 5: - C = np.asanyarray(args.pop(-1)) - V = np.asanyarray(args.pop(-1)) - U = np.asanyarray(args.pop(-1)) - if U.ndim == 1: - nr, nc = 1, U.shape[0] - else: - nr, nc = U.shape - if len(args) == 2: # remaining after removing U,V,C - X, Y = [np.array(a).ravel() for a in args] - if len(X) == nc and len(Y) == nr: - X, Y = [a.ravel() for a in np.meshgrid(X, Y)] - else: - indexgrid = np.meshgrid(np.arange(nc), np.arange(nr)) - X, Y = [np.ravel(a) for a in indexgrid] - return X, Y, U, V, C - def _init(self): """initialization delayed until first draw; allow time for axes setup. @@ -752,7 +755,7 @@ kw['facecolors'] = flagcolor #Parse out the data arrays from the various configurations supported - x, y, u, v, c = self._parse_args(*args) + x, y, u, v, c = _parse_args(*args) self.x = x self.y = y xy = np.hstack((x[:,np.newaxis], y[:,np.newaxis])) @@ -938,28 +941,6 @@ return barb_list - #Taken shamelessly from Quiver - def _parse_args(self, *args): - X, Y, U, V, C = [None]*5 - args = list(args) - if len(args) == 3 or len(args) == 5: - C = ma.masked_invalid(args.pop(-1), copy=False).ravel() - V = ma.masked_invalid(args.pop(-1), copy=False) - U = ma.masked_invalid(args.pop(-1), copy=False) - nn = np.shape(U) - nc = nn[0] - nr = 1 - if len(nn) > 1: - nr = nn[1] - if len(args) == 2: # remaining after removing U,V,C - X, Y = [np.array(a).ravel() for a in args] - if len(X) == nc and len(Y) == nr: - X, Y = [a.ravel() for a in np.meshgrid(X, Y)] - else: - indexgrid = np.meshgrid(np.arange(nc), np.arange(nr)) - X, Y = [np.ravel(a) for a in indexgrid] - return X, Y, U, V, C - def set_UVC(self, U, V, C=None): self.u = ma.masked_invalid(U, copy=False).ravel() self.v = ma.masked_invalid(V, copy=False).ravel() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins