From: <ef...@us...> - 2008-09-18 16:36:46
|
Revision: 6112 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6112&view=rev Author: efiring Date: 2008-09-18 23:36:43 +0000 (Thu, 18 Sep 2008) Log Message: ----------- Added angles kwarg to quiver, fixed bugs. Modified Paths: -------------- trunk/matplotlib/API_CHANGES trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/quiver.py Modified: trunk/matplotlib/API_CHANGES =================================================================== --- trunk/matplotlib/API_CHANGES 2008-09-18 20:33:18 UTC (rev 6111) +++ trunk/matplotlib/API_CHANGES 2008-09-18 23:36:43 UTC (rev 6112) @@ -2,6 +2,9 @@ Changes for 0.98.x ================== +* Added angles kwarg to quiver for more flexible specification of + the arrow angles. + * Deprecated (raise NotImplementedError) all the mlab2 functions from matplotlib.mlab out of concern that some of them were not clean room implementations. @@ -19,7 +22,7 @@ maintained for the moment (in addition to their renamed versions), but they are depricated and will eventually be removed. -* Moved several function in mlab.py and cbook.py into a separate module +* Moved several function in mlab.py and cbook.py into a separate module numerical_methods.py because they were unrelated to the initial purpose of mlab or cbook and appeared more coherent elsewhere. Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-09-18 20:33:18 UTC (rev 6111) +++ trunk/matplotlib/CHANGELOG 2008-09-18 23:36:43 UTC (rev 6112) @@ -1,11 +1,15 @@ +2008-09-18 Fixed quiver and quiverkey bugs (failure to scale properly + when resizing) and added additional methods for determining + the arrow angles - EF + 2008-09-18 Fix polar interpolation to handle negative values of theta - MGD 2008-09-14 Reorganized cbook and mlab methods related to numerical - calculations that have little to do with the goals of those two - modules into a separate module numerical_methods.py - Also, added ability to select points and stop point selection - with keyboard in ginput and manual contour labeling code. - Finally, fixed contour labeling bug. - DMK + calculations that have little to do with the goals of those two + modules into a separate module numerical_methods.py + Also, added ability to select points and stop point selection + with keyboard in ginput and manual contour labeling code. + Finally, fixed contour labeling bug. - DMK 2008-09-11 Fix backtick in Postscript output. - MGD Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-18 20:33:18 UTC (rev 6111) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-18 23:36:43 UTC (rev 6112) @@ -72,17 +72,21 @@ * 'x' or 'y': *X* or *Y* data units - In all cases the arrow aspect ratio is 1, so that if *U*==*V* the - angle of the arrow on the plot is 45 degrees CCW from the - *x*-axis. - - The arrows scale differently depending on the units, however. For + The arrows scale differently depending on the units. For 'x' or 'y', the arrows get larger as one zooms in; for other units, the arrow size is independent of the zoom state. For 'width or 'height', the arrow size increases with the width and height of the axes, respectively, when the the window is resized; for 'dots' or 'inches', resizing does not change the arrows. + *angles*: ['uv' | 'xy' | array] + With the default 'uv', the arrow aspect ratio is 1, so that + if *U*==*V* the angle of the arrow on the plot is 45 degrees + CCW from the *x*-axis. + With 'xy', the arrow points from (x,y) to (x+u, y+v). + Alternatively, arbitrary angles may be specified as an array + of values in radians, CCW from the *x*-axis. + *scale*: [ None | float ] data units per arrow unit, e.g. m/s per plot width; a smaller scale parameter makes the arrow longer. If *None*, a simple @@ -244,7 +248,7 @@ __init__.__doc__ = _quiverkey_doc def _init(self): - if not self._initialized: + if True: ##not self._initialized: self._set_transform() _pivot = self.Q.pivot self.Q.pivot = self.pivot[self.labelpos] @@ -345,6 +349,7 @@ self.minshaft = kw.pop('minshaft', 1) self.minlength = kw.pop('minlength', 1) self.units = kw.pop('units', 'width') + self.angles = kw.pop('angles', 'uv') self.width = kw.pop('width', None) self.color = kw.pop('color', 'k') self.pivot = kw.pop('pivot', 'tail') @@ -402,7 +407,9 @@ """initialization delayed until first draw; allow time for axes setup. """ - if not self._initialized: + # It seems that there are not enough event notifications + # available to have this work on an as-needed basis at present. + if True: ##not self._initialized: trans = self._set_transform() ax = self.ax sx, sy = trans.inverted().transform_point( @@ -414,7 +421,7 @@ def draw(self, renderer): self._init() - if self._new_UV: + if self._new_UV or self.angles == 'xy': verts = self._make_verts(self.U, self.V) self.set_verts(verts, closed=False) self._new_UV = False @@ -452,6 +459,14 @@ self.set_transform(trans) return trans + def _angles(self, U, V, eps=0.001): + xy = self.ax.transData.transform(self.XY) + uv = ma.hstack((U[:,np.newaxis], V[:,np.newaxis])).filled(0) + xyp = self.ax.transData.transform(self.XY + eps * uv) + dxy = xyp - xy + ang = ma.arctan2(dxy[:,1], dxy[:,0]) + return ang + def _make_verts(self, U, V): uv = ma.asarray(U+V*1j) a = ma.absolute(uv) @@ -461,10 +476,12 @@ self.scale = scale length = a/(self.scale*self.width) X, Y = self._h_arrows(length) - # There seems to be a ma bug such that indexing - # a masked array with one element converts it to - # an ndarray. - theta = np.angle(ma.asarray(uv[..., np.newaxis]).filled(0)) + if self.angles == 'xy': + theta = self._angles(U, V).filled(0) + elif self.angles == 'uv': + theta = np.angle(ma.asarray(uv[..., np.newaxis]).filled(0)) + else: + theta = ma.asarray(self.angles).filled(0) xy = (X+Y*1j) * np.exp(1j*theta)*self.width xy = xy[:,:,np.newaxis] XY = ma.concatenate((xy.real, xy.imag), axis=2) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |