Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc98579

Browse files
committed
updated api for fill_between_where and span_where
svn path=/trunk/matplotlib/; revision=6434
1 parent f5313df commit bc98579

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

examples/api/fill_where_demo.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
Illustrate some helper functions for shading regions where a logical
33
mask is True
4+
5+
See :meth:`matplotlib.collections.PolyCollection.fill_between_where`
6+
and :meth:`matplotlib.collections.BrokenBarHCollection.span_where`
47
"""
58
import numpy as np
69
import matplotlib.pyplot as plt
@@ -18,26 +21,26 @@
1821
ax.axhline(0, color='black', lw=2)
1922

2023
collection = collections.PolyCollection.fill_between_where(
21-
t, s1, s2, s1>=s2, color='green', alpha=0.5)
24+
t, s1, s2, where=s1>=s2, color='green', alpha=0.5)
2225
ax.add_collection(collection)
2326

2427
collection = collections.PolyCollection.fill_between_where(
25-
t, s1, s2, s1<=s2, color='red', alpha=0.5)
28+
t, s1, s2, where=s1<=s2, color='red', alpha=0.5)
2629
ax.add_collection(collection)
2730

2831

2932
fig = plt.figure()
3033
ax = fig.add_subplot(111)
31-
ax.set_title('using span_masked')
34+
ax.set_title('using span_where')
3235
ax.plot(t, s1, '-')
3336
ax.axhline(0, color='black', lw=2)
3437

35-
collection = collections.BrokenBarHCollection.span_masked(
36-
t, s1>0, ymin=0, ymax=1, facecolor='green', alpha=0.5)
38+
collection = collections.BrokenBarHCollection.span_where(
39+
t, ymin=0, ymax=1, where=s1>0, facecolor='green', alpha=0.5)
3740
ax.add_collection(collection)
3841

39-
collection = collections.BrokenBarHCollection.span_masked(
40-
t, s1<0, ymin=-1, ymax=0, facecolor='red', alpha=0.5)
42+
collection = collections.BrokenBarHCollection.span_where(
43+
t, ymin=-1, ymax=0, where=s1<0, facecolor='red', alpha=0.5)
4144
ax.add_collection(collection)
4245

4346

lib/matplotlib/collections.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,10 @@ def draw(self, renderer):
674674

675675

676676
@staticmethod
677-
def fill_between_where(x, y1, y2, mask, **kwargs):
677+
def fill_between_where(x, y1, y2, where, **kwargs):
678678
"""
679679
Create a :class:`PolyCollection` filling the regions between *y*
680-
and *yboundary7* where ``mask==True``
680+
and *yboundary7* where ``where==True``
681681
682682
683683
*x*
@@ -689,7 +689,7 @@ def fill_between_where(x, y1, y2, mask, **kwargs):
689689
*y2*
690690
an N length scalar or np array of the x data
691691
692-
*mask*
692+
*where*
693693
an N length numpy boolean array
694694
695695
*kwargs*
@@ -705,7 +705,7 @@ def fill_between_where(x, y1, y2, mask, **kwargs):
705705
assert( (len(x)==len(y1)) and (len(x)==len(y2)) )
706706

707707
polys = []
708-
for ind0, ind1 in mlab.contiguous_regions(mask):
708+
for ind0, ind1 in mlab.contiguous_regions(where):
709709
theseverts = []
710710
xslice = x[ind0:ind1]
711711
y1slice = y1[ind0:ind1]
@@ -756,17 +756,17 @@ def __init__(self, xranges, yrange, **kwargs):
756756

757757

758758
@staticmethod
759-
def span_masked(x, mask, ymin, ymax, **kwargs):
759+
def span_where(x, ymin, ymax, where, **kwargs):
760760
"""
761761
Create a BrokenBarHCollection to plot horizontal bars from
762-
over the regions in *x* where *mask* is True. The bars range
762+
over the regions in *x* where *where* is True. The bars range
763763
on the y-axis from *ymin* to *ymax*
764764
765765
A :class:`BrokenBarHCollection` is returned.
766766
**kwargs are passed on to the collection
767767
"""
768768
xranges = []
769-
for ind0, ind1 in mlab.contiguous_regions(mask):
769+
for ind0, ind1 in mlab.contiguous_regions(where):
770770
xslice = x[ind0:ind1]
771771
if not len(xslice):
772772
continue

0 commit comments

Comments
 (0)