@@ -5826,10 +5826,10 @@ def fill_between(self, x, y1, y2=0, where=None, **kwargs):
58265826 an N length np array of the x data
58275827
58285828 *y1*
5829- an N length scalar or np array of the x data
5829+ an N length scalar or np array of the y data
58305830
58315831 *y2*
5832- an N length scalar or np array of the x data
5832+ an N length scalar or np array of the y data
58335833
58345834 *where*
58355835 if None, default to fill between everywhere. If not None,
@@ -5844,6 +5844,12 @@ def fill_between(self, x, y1, y2=0, where=None, **kwargs):
58445844 %(PolyCollection)s
58455845
58465846 .. plot:: mpl_examples/pylab_examples/fill_between.py
5847+
5848+ .. seealso::
5849+
5850+ :meth:`fill_betweenx`
5851+ for filling between two sets of x-values
5852+
58475853 """
58485854 # Handle united data, such as dates
58495855 self ._process_unit_info (xdata = x , ydata = y1 , kwargs = kwargs )
@@ -5913,6 +5919,113 @@ def fill_between(self, x, y1, y2=0, where=None, **kwargs):
59135919 return collection
59145920 fill_between .__doc__ = cbook .dedent (fill_between .__doc__ ) % martist .kwdocd
59155921
5922+ def fill_betweenx (self , y , x1 , x2 = 0 , where = None , ** kwargs ):
5923+ """
5924+ call signature::
5925+
5926+ fill_between(y, x1, x2=0, where=None, **kwargs)
5927+
5928+ Create a :class:`~matplotlib.collections.PolyCollection`
5929+ filling the regions between *x1* and *x2* where
5930+ ``where==True``
5931+
5932+ *y*
5933+ an N length np array of the y data
5934+
5935+ *x1*
5936+ an N length scalar or np array of the x data
5937+
5938+ *x2*
5939+ an N length scalar or np array of the x data
5940+
5941+ *where*
5942+ if None, default to fill between everywhere. If not None,
5943+ it is a a N length numpy boolean array and the fill will
5944+ only happen over the regions where ``where==True``
5945+
5946+ *kwargs*
5947+ keyword args passed on to the :class:`PolyCollection`
5948+
5949+ kwargs control the Polygon properties:
5950+
5951+ %(PolyCollection)s
5952+
5953+ .. plot:: mpl_examples/pylab_examples/fill_betweenx.py
5954+
5955+ .. seealso::
5956+
5957+ :meth:`fill_between`
5958+ for filling between two sets of y-values
5959+
5960+ """
5961+ # Handle united data, such as dates
5962+ self ._process_unit_info (ydata = y , xdata = x1 , kwargs = kwargs )
5963+ self ._process_unit_info (xdata = x2 )
5964+
5965+ # Convert the arrays so we can work with them
5966+ y = np .asanyarray (self .convert_yunits (y ))
5967+ x1 = np .asanyarray (self .convert_xunits (x1 ))
5968+ x2 = np .asanyarray (self .convert_xunits (x2 ))
5969+
5970+ if x1 .ndim == 0 :
5971+ x1 = np .ones_like (y )* x1
5972+ if x2 .ndim == 0 :
5973+ x2 = np .ones_like (y )* x2
5974+
5975+ if where is None :
5976+ where = np .ones (len (y ), np .bool )
5977+ else :
5978+ where = np .asarray (where , np .bool )
5979+
5980+ if not (y .shape == x1 .shape == x2 .shape == where .shape ):
5981+ raise ValueError ("Argument dimensions are incompatible" )
5982+
5983+ mask = reduce (ma .mask_or ,
5984+ [ma .getmask (y ), ma .getmask (x1 ), ma .getmask (x2 )])
5985+ if mask is not ma .nomask :
5986+ where &= ~ mask
5987+
5988+ polys = []
5989+ for ind0 , ind1 in mlab .contiguous_regions (where ):
5990+ theseverts = []
5991+ yslice = y [ind0 :ind1 ]
5992+ x1slice = x1 [ind0 :ind1 ]
5993+ x2slice = x2 [ind0 :ind1 ]
5994+
5995+ if not len (yslice ):
5996+ continue
5997+
5998+ N = len (yslice )
5999+ Y = np .zeros ((2 * N + 2 , 2 ), np .float )
6000+
6001+ # the purpose of the next two lines is for when x2 is a
6002+ # scalar like 0 and we want the fill to go all the way
6003+ # down to 0 even if none of the x1 sample points do
6004+ Y [0 ] = x2slice [0 ], yslice [0 ]
6005+ Y [N + 1 ] = x2slice [- 1 ], yslice [- 1 ]
6006+
6007+ Y [1 :N + 1 ,0 ] = x1slice
6008+ Y [1 :N + 1 ,1 ] = yslice
6009+ Y [N + 2 :,0 ] = x2slice [::- 1 ]
6010+ Y [N + 2 :,1 ] = yslice [::- 1 ]
6011+
6012+ polys .append (Y )
6013+
6014+ collection = mcoll .PolyCollection (polys , ** kwargs )
6015+
6016+ # now update the datalim and autoscale
6017+ X1Y = np .array ([x1 [where ], y [where ]]).T
6018+ X2Y = np .array ([x2 [where ], y [where ]]).T
6019+ self .dataLim .update_from_data_xy (X1Y , self .ignore_existing_data_limits ,
6020+ updatex = True , updatey = True )
6021+
6022+ self .dataLim .update_from_data_xy (X2Y , self .ignore_existing_data_limits ,
6023+ updatex = False , updatey = True )
6024+ self .add_collection (collection )
6025+ self .autoscale_view ()
6026+ return collection
6027+ fill_between .__doc__ = cbook .dedent (fill_between .__doc__ ) % martist .kwdocd
6028+
59166029 #### plotting z(x,y): imshow, pcolor and relatives, contour
59176030
59186031 def imshow (self , X , cmap = None , norm = None , aspect = None ,
0 commit comments