Revision: 7079
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7079&view=rev
Author:   jdh2358
Date:     2009-05-04 18:19:18 +0000 (Mon, 04 May 2009)

Log Message:
-----------
added sf patch 2786759 for fill_betweenx

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/boilerplate.py
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/pyplot.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-05-03 00:09:06 UTC (rev 7078)
+++ trunk/matplotlib/CHANGELOG  2009-05-04 18:19:18 UTC (rev 7079)
@@ -1,7 +1,10 @@
 ======================================================================
+2009-05-04 Added TJ's fill_betweenx patch - JDH
+
 2009-05-02 Added options to plotfile based on question from
            Joseph Smidt and patch by Matthias Michler. - EF
 
+
 2009-05-01 Changed add_artist and similar Axes methods to
            return their argument. - EF
 

Modified: trunk/matplotlib/boilerplate.py
===================================================================
--- trunk/matplotlib/boilerplate.py     2009-05-03 00:09:06 UTC (rev 7078)
+++ trunk/matplotlib/boilerplate.py     2009-05-04 18:19:18 UTC (rev 7079)
@@ -65,6 +65,7 @@
     'errorbar',
     'fill',
     'fill_between',
+    'fill_betweenx',
     'hexbin',
     'hist',
     'hlines',

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2009-05-03 00:09:06 UTC (rev 
7078)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2009-05-04 18:19:18 UTC (rev 
7079)
@@ -5826,10 +5826,10 @@
           an N length np array of the x data
 
         *y1*
-          an N length scalar or np array of the x data
+          an N length scalar or np array of the y data
 
         *y2*
-          an N length scalar or np array of the x data
+          an N length scalar or np array of the y data
 
         *where*
            if None, default to fill between everywhere.  If not None,
@@ -5844,6 +5844,12 @@
         %(PolyCollection)s
 
         .. plot:: mpl_examples/pylab_examples/fill_between.py
+
+        .. seealso::
+
+            :meth:`fill_betweenx`
+                for filling between two sets of x-values
+
         """
         # Handle united data, such as dates
         self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs)
@@ -5913,6 +5919,113 @@
         return collection
     fill_between.__doc__ = cbook.dedent(fill_between.__doc__) % martist.kwdocd
 
+    def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
+        """
+        call signature::
+
+          fill_between(y, x1, x2=0, where=None, **kwargs)
+
+        Create a :class:`~matplotlib.collections.PolyCollection`
+        filling the regions between *x1* and *x2* where
+        ``where==True``
+
+        *y*
+          an N length np array of the y data
+
+        *x1*
+          an N length scalar or np array of the x data
+
+        *x2*
+          an N length scalar or np array of the x data
+
+        *where*
+           if None, default to fill between everywhere.  If not None,
+           it is a a N length numpy boolean array and the fill will
+           only happen over the regions where ``where==True``
+
+        *kwargs*
+          keyword args passed on to the :class:`PolyCollection`
+
+        kwargs control the Polygon properties:
+
+        %(PolyCollection)s
+
+        .. plot:: mpl_examples/pylab_examples/fill_betweenx.py
+
+        .. seealso::
+
+            :meth:`fill_between`
+                for filling between two sets of y-values
+
+        """
+        # Handle united data, such as dates
+        self._process_unit_info(ydata=y, xdata=x1, kwargs=kwargs)
+        self._process_unit_info(xdata=x2)
+
+        # Convert the arrays so we can work with them
+        y = np.asanyarray(self.convert_yunits(y))
+        x1 = np.asanyarray(self.convert_xunits(x1))
+        x2 = np.asanyarray(self.convert_xunits(x2))
+
+        if x1.ndim == 0:
+            x1 = np.ones_like(y)*x1
+        if x2.ndim == 0:
+            x2 = np.ones_like(y)*x2
+
+        if where is None:
+            where = np.ones(len(y), np.bool)
+        else:
+            where = np.asarray(where, np.bool)
+
+        if not (y.shape == x1.shape == x2.shape == where.shape):
+            raise ValueError("Argument dimensions are incompatible")
+
+        mask = reduce(ma.mask_or,
+                        [ma.getmask(y), ma.getmask(x1), ma.getmask(x2)])
+        if mask is not ma.nomask:
+            where &= ~mask
+
+        polys = []
+        for ind0, ind1 in mlab.contiguous_regions(where):
+            theseverts = []
+            yslice = y[ind0:ind1]
+            x1slice = x1[ind0:ind1]
+            x2slice = x2[ind0:ind1]
+
+            if not len(yslice):
+                continue
+
+            N = len(yslice)
+            Y = np.zeros((2*N+2, 2), np.float)
+
+            # the purpose of the next two lines is for when x2 is a
+            # scalar like 0 and we want the fill to go all the way
+            # down to 0 even if none of the x1 sample points do
+            Y[0] = x2slice[0], yslice[0]
+            Y[N+1] = x2slice[-1], yslice[-1]
+
+            Y[1:N+1,0] = x1slice
+            Y[1:N+1,1] = yslice
+            Y[N+2:,0] = x2slice[::-1]
+            Y[N+2:,1] = yslice[::-1]
+
+            polys.append(Y)
+
+        collection = mcoll.PolyCollection(polys, **kwargs)
+
+        # now update the datalim and autoscale
+        X1Y = np.array([x1[where], y[where]]).T
+        X2Y = np.array([x2[where], y[where]]).T
+        self.dataLim.update_from_data_xy(X1Y, self.ignore_existing_data_limits,
+                                         updatex=True, updatey=True)
+
+        self.dataLim.update_from_data_xy(X2Y, self.ignore_existing_data_limits,
+                                         updatex=False, updatey=True)
+        self.add_collection(collection)
+        self.autoscale_view()
+        return collection
+    fill_between.__doc__ = cbook.dedent(fill_between.__doc__) % martist.kwdocd
+
     #### plotting z(x,y): imshow, pcolor and relatives, contour
 
     def imshow(self, X, cmap=None, norm=None, aspect=None,

Modified: trunk/matplotlib/lib/matplotlib/pyplot.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/pyplot.py   2009-05-03 00:09:06 UTC (rev 
7078)
+++ trunk/matplotlib/lib/matplotlib/pyplot.py   2009-05-04 18:19:18 UTC (rev 
7079)
@@ -1185,7 +1185,8 @@
     figtext         add text in figure coords
     figure          create or change active figure
     fill            make filled polygons
-    fill_between    make filled polygons
+    fill_between    make filled polygons between two sets of y-values
+    fill_betweenx   make filled polygons between two sets of x-values
     gca             return the current axes
     gcf             return the current figure
     gci             get the current image, or None
@@ -1973,6 +1974,28 @@
 
 # This function was autogenerated by boilerplate.py.  Do not edit as
 # changes will be lost
+def fill_betweenx(*args, **kwargs):
+    # allow callers to override the hold state by passing hold=True|False
+    b = ishold()
+    h = kwargs.pop('hold', None)
+    if h is not None:
+        hold(h)
+    try:
+        ret =  gca().fill_betweenx(*args, **kwargs)
+        draw_if_interactive()
+    except:
+        hold(b)
+        raise
+
+    hold(b)
+    return ret
+if Axes.fill_betweenx.__doc__ is not None:
+    fill_betweenx.__doc__ = dedent(Axes.fill_betweenx.__doc__) + """
+
+Additional kwargs: hold = [True|False] overrides default hold state"""
+
+# This function was autogenerated by boilerplate.py.  Do not edit as
+# changes will be lost
 def hexbin(*args, **kwargs):
     # allow callers to override the hold state by passing hold=True|False
     b = ishold()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to