@@ -1302,6 +1302,7 @@ def add_collection(self, collection, autolim=True):
13021302 if autolim :
13031303 if collection ._paths and len (collection ._paths ):
13041304 self .update_datalim (collection .get_datalim (self .transData ))
1305+
13051306 collection ._remove_method = lambda h : self .collections .remove (h )
13061307
13071308 def add_line (self , line ):
@@ -5456,11 +5457,7 @@ def fill(self, *args, **kwargs):
54565457 supports are supported by the fill format string.
54575458
54585459 If you would like to fill below a curve, eg. shade a region
5459- between 0 and *y* along *x*, use
5460- :func:`~matplotlib.pylab.poly_between`, eg.::
5461-
5462- xs, ys = poly_between(x, 0, y)
5463- axes.fill(xs, ys, facecolor='red', alpha=0.5)
5460+ between 0 and *y* along *x*, use :meth:`fill_between`
54645461
54655462 The *closed* kwarg will close the polygon when *True* (default).
54665463
@@ -5472,9 +5469,6 @@ def fill(self, *args, **kwargs):
54725469
54735470 .. plot:: mpl_examples/pylab_examples/fill_demo.py
54745471
5475- .. seealso::
5476- :file:`examples/pylab_examples/fill_between.py`:
5477- For more examples.
54785472 """
54795473 if not self ._hold : self .cla ()
54805474
@@ -5486,6 +5480,92 @@ def fill(self, *args, **kwargs):
54865480 return patches
54875481 fill .__doc__ = cbook .dedent (fill .__doc__ ) % martist .kwdocd
54885482
5483+ def fill_between (self , x , y1 , y2 = 0 , where = None , ** kwargs ):
5484+ """
5485+ call signature::
5486+
5487+ fill_between(x, y1, y2=0, where=None, **kwargs)
5488+
5489+ Create a :class:`~matplotlib.collectionsPolyCollection`
5490+ filling the regions between *y1* and *y2* where
5491+ ``where==True``
5492+
5493+ *x*
5494+ an N length np array of the x data
5495+
5496+ *y1*
5497+ an N length scalar or np array of the x data
5498+
5499+ *y2*
5500+ an N length scalar or np array of the x data
5501+
5502+ *where*
5503+ if None, default to fill between everywhere. If not None,
5504+ it is a a N length numpy boolean array and the fill will
5505+ only happen over the regions where ``where==True``
5506+
5507+ *kwargs*
5508+ keyword args passed on to the :class:`PolyCollection`
5509+
5510+ .. seealso::
5511+ :file:`examples/pylab_examples/fill_between.py`:
5512+ For more examples.
5513+
5514+ kwargs control the Polygon properties:
5515+
5516+ %(PolyCollection)s
5517+
5518+ """
5519+ x = np .asarray (x )
5520+ if not cbook .iterable (y1 ):
5521+ y1 = np .ones_like (x )* y1
5522+
5523+ if not cbook .iterable (y2 ):
5524+ y2 = np .ones_like (x )* y2
5525+
5526+ if where is None :
5527+ where = np .ones (len (x ), np .bool )
5528+
5529+ y1 = np .asarray (y1 )
5530+ y2 = np .asarray (y2 )
5531+ where = np .asarray (where )
5532+ assert ( (len (x )== len (y1 )) and (len (x )== len (y2 )) and len (x )== len (where ))
5533+
5534+ polys = []
5535+ for ind0 , ind1 in mlab .contiguous_regions (where ):
5536+ theseverts = []
5537+ xslice = x [ind0 :ind1 ]
5538+ y1slice = y1 [ind0 :ind1 ]
5539+ y2slice = y2 [ind0 :ind1 ]
5540+
5541+ if not len (xslice ):
5542+ continue
5543+
5544+ N = len (xslice )
5545+ X = np .zeros ((2 * N + 2 , 2 ), np .float )
5546+
5547+ # the purpose of the next two lines is for when y2 is a
5548+ # scalar like 0 and we want the fill to go all the way
5549+ # down to 0 even if none of the y1 sample points do
5550+ X [0 ] = xslice [0 ], y2slice [0 ]
5551+ X [N + 1 ] = xslice [- 1 ], y2slice [- 1 ]
5552+
5553+ X [1 :N + 1 ,0 ] = xslice
5554+ X [1 :N + 1 ,1 ] = y1slice
5555+ X [N + 2 :,0 ] = xslice [::- 1 ]
5556+ X [N + 2 :,1 ] = y2slice [::- 1 ]
5557+
5558+ polys .append (X )
5559+
5560+ collection = mcoll .PolyCollection (polys , ** kwargs )
5561+
5562+ self .update_datalim_numerix (x [where ], y1 [where ])
5563+ self .update_datalim_numerix (x [where ], y2 [where ])
5564+ self .add_collection (collection )
5565+ self .autoscale_view ()
5566+ return collection
5567+ fill_between .__doc__ = cbook .dedent (fill_between .__doc__ ) % martist .kwdocd
5568+
54895569 #### plotting z(x,y): imshow, pcolor and relatives, contour
54905570
54915571 def imshow (self , X , cmap = None , norm = None , aspect = None ,
0 commit comments