Skip to content

Commit 1c86c63

Browse files
committed
added sf patch 2786759 for fill_betweenx
svn path=/trunk/matplotlib/; revision=7079
1 parent bdc188f commit 1c86c63

File tree

4 files changed

+143
-3
lines changed

4 files changed

+143
-3
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
======================================================================
2+
2009-05-04 Added TJ's fill_betweenx patch - JDH
3+
24
2009-05-02 Added options to plotfile based on question from
35
Joseph Smidt and patch by Matthias Michler. - EF
46

7+
58
2009-05-01 Changed add_artist and similar Axes methods to
69
return their argument. - EF
710

boilerplate.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def %(func)s(*args, **kwargs):
6565
'errorbar',
6666
'fill',
6767
'fill_between',
68+
'fill_betweenx',
6869
'hexbin',
6970
'hist',
7071
'hlines',

lib/matplotlib/axes.py

+115-2
Original file line numberDiff line numberDiff line change
@@ -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,

lib/matplotlib/pyplot.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,8 @@ def plotting():
11851185
figtext add text in figure coords
11861186
figure create or change active figure
11871187
fill make filled polygons
1188-
fill_between make filled polygons
1188+
fill_between make filled polygons between two sets of y-values
1189+
fill_betweenx make filled polygons between two sets of x-values
11891190
gca return the current axes
11901191
gcf return the current figure
11911192
gci get the current image, or None
@@ -1971,6 +1972,28 @@ def fill_between(*args, **kwargs):
19711972
19721973
Additional kwargs: hold = [True|False] overrides default hold state"""
19731974

1975+
# This function was autogenerated by boilerplate.py. Do not edit as
1976+
# changes will be lost
1977+
def fill_betweenx(*args, **kwargs):
1978+
# allow callers to override the hold state by passing hold=True|False
1979+
b = ishold()
1980+
h = kwargs.pop('hold', None)
1981+
if h is not None:
1982+
hold(h)
1983+
try:
1984+
ret = gca().fill_betweenx(*args, **kwargs)
1985+
draw_if_interactive()
1986+
except:
1987+
hold(b)
1988+
raise
1989+
1990+
hold(b)
1991+
return ret
1992+
if Axes.fill_betweenx.__doc__ is not None:
1993+
fill_betweenx.__doc__ = dedent(Axes.fill_betweenx.__doc__) + """
1994+
1995+
Additional kwargs: hold = [True|False] overrides default hold state"""
1996+
19741997
# This function was autogenerated by boilerplate.py. Do not edit as
19751998
# changes will be lost
19761999
def hexbin(*args, **kwargs):

0 commit comments

Comments
 (0)