From: <ry...@us...> - 2008-07-25 01:43:45
|
Revision: 5861 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5861&view=rev Author: ryanmay Date: 2008-07-25 01:43:43 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Add support for flipping which side of the barb the features are drawn. Useful to the meteorologists in the southern hemisphere plus anyone who might have an aesthetic preference. Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/barb_demo.py trunk/matplotlib/lib/matplotlib/quiver.py Modified: trunk/matplotlib/examples/pylab_examples/barb_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-24 22:50:41 UTC (rev 5860) +++ trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-25 01:43:43 UTC (rev 5861) @@ -36,6 +36,7 @@ #Change colors as well as the increments for parts of the barbs ax = plt.subplot(2,2,4) ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r', - barbcolor=['b','g'], barb_increments=dict(half=10, full=20, flag=100)) + barbcolor=['b','g'], barb_increments=dict(half=10, full=20, flag=100), + flip_barb=True) plt.show() Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2008-07-24 22:50:41 UTC (rev 5860) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2008-07-25 01:43:43 UTC (rev 5861) @@ -592,6 +592,16 @@ 'half' - half barbs (Default is 5) 'full' - full barbs (Default is 10) 'flag' - flags (default is 50) + + *flip_barb*: + Either a single boolean flag or an array of booleans. Single boolean + indicates whether the lines and flags should point opposite to normal + for all barbs. An array (which should be the same size as the other + data arrays) indicates whether to flip for each individual barb. + Normal behavior is for the barbs and lines to point right (comes from + wind barbs having these features point towards low pressure in the + Northern Hemisphere.) + Default is False Barbs are traditionally used in meteorology as a way to plot the speed and direction of wind observations, but can technically be used to plot @@ -647,7 +657,8 @@ self.fill_empty = kw.pop('fill_empty', False) self.barb_increments = kw.pop('barb_increments', dict()) self.rounding = kw.pop('rounding', True) - + self.flip = kw.pop('flip_barb', False) + #Flagcolor and and barbcolor provide convenience parameters for setting #the facecolor and edgecolor, respectively, of the barb polygon. We #also work here to make the flag the same color as the rest of the barb @@ -714,7 +725,7 @@ return num_flags, num_barb, half_flag, empty_flag def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length, - pivot, sizes, fill_empty): + pivot, sizes, fill_empty, flip): '''This function actually creates the wind barbs. u and v are components of the vector in the x and y directions, respectively. nflags, nbarbs, and half_barb, empty_flag are, respectively, the number @@ -730,7 +741,13 @@ height - height (distance from shaft of top) of a flag or full barb width - width of a flag, twice the width of a full barb emptybarb - radius of the circle used for low magnitudes - + + fill_empty specifies whether the circle representing an empty barb + should be filled or not (this changes the drawing of the polygon). + flip is a flag indicating whether the features should be flipped to + the other side of the barb (useful for winds in the southern + hemisphere. + This function returns list of arrays of vertices, defining a polygon for each of the wind barbs. These polygons have been rotated to properly align with the vector direction.''' @@ -744,6 +761,9 @@ #Controls y point where to pivot the barb. pivot_points = dict(tip=0.0, middle=-length/2.) + + #Check for flip + if flip: full_height = -full_height endx = 0.0 endy = pivot_points[pivot.lower()] @@ -861,7 +881,7 @@ #Get the vertices for each of the barbs plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty, - self._length, self._pivot, self.sizes, self.fill_empty) + self._length, self._pivot, self.sizes, self.fill_empty, self.flip) self.set_verts(plot_barbs) #Set the color array This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |