Skip to content

Commit efced7d

Browse files
committed
ENH : add step_where kwarg to fill_between{x}
Add ability to fill between 'step' plots. Closes matplotlib#643 and matplotlib#1709
1 parent 815e9cb commit efced7d

1 file changed

Lines changed: 35 additions & 15 deletions

File tree

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import matplotlib
1414

1515
import matplotlib.cbook as cbook
16-
from matplotlib.cbook import _string_to_bool, mplDeprecation
16+
from matplotlib.cbook import mplDeprecation, STEP_LOOKUP_MAP
1717
import matplotlib.collections as mcoll
1818
import matplotlib.colors as mcolors
1919
import matplotlib.contour as mcontour
@@ -4370,13 +4370,11 @@ def fill(self, *args, **kwargs):
43704370

43714371
@docstring.dedent_interpd
43724372
def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
4373+
step_where=None,
43734374
**kwargs):
43744375
"""
43754376
Make filled polygons between two curves.
43764377
4377-
Call signature::
4378-
4379-
fill_between(x, y1, y2=0, where=None, **kwargs)
43804378
43814379
Create a :class:`~matplotlib.collections.PolyCollection`
43824380
filling the regions between *y1* and *y2* where
@@ -4404,9 +4402,12 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
44044402
end points of the filled region will only occur on explicit
44054403
values in the *x* array.
44064404
4405+
step_where : {'pre', 'post', 'mid'}, optional
4406+
If not None, fill with step logic.
4407+
44074408
4408-
Note
4409-
----
4409+
Notes
4410+
-----
44104411
44114412
Additional Keyword args passed on to the
44124413
:class:`~matplotlib.collections.PolyCollection`.
@@ -4458,6 +4459,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
44584459
xslice = x[ind0:ind1]
44594460
y1slice = y1[ind0:ind1]
44604461
y2slice = y2[ind0:ind1]
4462+
if step_where is not None:
4463+
step_func = STEP_LOOKUP_MAP[step_where]
4464+
xslice, y1slice, y2slice = step_func(xslice, y1slice, y2slice)
44614465

44624466
if not len(xslice):
44634467
continue
@@ -4518,7 +4522,8 @@ def get_interp_point(ind):
45184522
return collection
45194523

45204524
@docstring.dedent_interpd
4521-
def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
4525+
def fill_betweenx(self, y, x1, x2=0, where=None,
4526+
step_where=None, **kwargs):
45224527
"""
45234528
Make filled polygons between two horizontal curves.
45244529
@@ -4530,19 +4535,27 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
45304535
filling the regions between *x1* and *x2* where
45314536
``where==True``
45324537
4533-
*y* :
4538+
Parameters
4539+
----------
4540+
y : array
45344541
An N-length array of the y data
45354542
4536-
*x1* :
4543+
x1 : array
45374544
An N-length array (or scalar) of the x data
45384545
4539-
*x2* :
4546+
x2 : array, optional
45404547
An N-length array (or scalar) of the x data
45414548
4542-
*where* :
4543-
If *None*, default to fill between everywhere. If not *None*,
4544-
it is a N length numpy boolean array and the fill will
4545-
only happen over the regions where ``where==True``
4549+
where : array, optional
4550+
If *None*, default to fill between everywhere. If not *None*,
4551+
it is a N length numpy boolean array and the fill will
4552+
only happen over the regions where ``where==True``
4553+
4554+
step_where : {'pre', 'post', 'mid'}, optional
4555+
If not None, fill with step logic.
4556+
4557+
Notes
4558+
-----
45464559
45474560
*kwargs* :
45484561
keyword args passed on to the
@@ -4552,9 +4565,13 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
45524565
45534566
%(PolyCollection)s
45544567
4568+
Examples
4569+
--------
4570+
45554571
.. plot:: mpl_examples/pylab_examples/fill_betweenx_demo.py
45564572
4557-
.. seealso::
4573+
See Also
4574+
--------
45584575
45594576
:meth:`fill_between`
45604577
for filling between two sets of y-values
@@ -4591,6 +4608,9 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
45914608
yslice = y[ind0:ind1]
45924609
x1slice = x1[ind0:ind1]
45934610
x2slice = x2[ind0:ind1]
4611+
if step_where is not None:
4612+
step_func = STEP_LOOKUP_MAP[step_where]
4613+
yslice, x1slice, x2slice = step_func(yslice, x1slice, x2slice)
45944614

45954615
if not len(yslice):
45964616
continue

0 commit comments

Comments
 (0)