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

Skip to content

Commit 1f1c6fb

Browse files
committed
Move contiguous_regions to cbook
1 parent 221460b commit 1f1c6fb

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,7 +4846,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
48464846
x, y1, y2 = np.broadcast_arrays(np.atleast_1d(x), y1, y2)
48474847

48484848
polys = []
4849-
for ind0, ind1 in mlab.contiguous_regions(where):
4849+
for ind0, ind1 in cbook.contiguous_regions(where):
48504850
xslice = x[ind0:ind1]
48514851
y1slice = y1[ind0:ind1]
48524852
y2slice = y2[ind0:ind1]
@@ -4997,7 +4997,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49974997
y, x1, x2 = np.broadcast_arrays(np.atleast_1d(y), x1, x2)
49984998

49994999
polys = []
5000-
for ind0, ind1 in mlab.contiguous_regions(where):
5000+
for ind0, ind1 in cbook.contiguous_regions(where):
50015001
yslice = y[ind0:ind1]
50025002
x1slice = x1[ind0:ind1]
50035003
x2slice = x2[ind0:ind1]

lib/matplotlib/cbook/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,32 @@ def __call__(self, key):
20242024
break
20252025

20262026

2027+
def contiguous_regions(mask):
2028+
"""
2029+
Return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
2030+
True and we cover all such regions
2031+
"""
2032+
mask = np.asarray(mask, dtype=bool)
2033+
2034+
if not mask.size:
2035+
return []
2036+
2037+
# Find the indices of region changes, and correct offset
2038+
idx, = np.nonzero(mask[:-1] != mask[1:])
2039+
idx += 1
2040+
2041+
# List operations are faster for moderately sized arrays
2042+
idx = idx.tolist()
2043+
2044+
# Add first and/or last index if needed
2045+
if mask[0]:
2046+
idx = [0] + idx
2047+
if mask[-1]:
2048+
idx.append(len(mask))
2049+
2050+
return list(zip(idx[::2], idx[1::2]))
2051+
2052+
20272053
def is_math_text(s):
20282054
# Did we find an even number of non-escaped dollar signs?
20292055
# If so, treat is as math text.

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def span_where(x, ymin, ymax, where, **kwargs):
971971
passed on to the collection.
972972
"""
973973
xranges = []
974-
for ind0, ind1 in mlab.contiguous_regions(where):
974+
for ind0, ind1 in cbook.contiguous_regions(where):
975975
xslice = x[ind0:ind1]
976976
if not len(xslice):
977977
continue

lib/matplotlib/mlab.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,30 +3877,13 @@ def is_closed_polygon(X):
38773877
return np.all(X[0] == X[-1])
38783878

38793879

3880+
@cbook.deprecated("2.2", message='Moved to matplotlib.cbook')
38803881
def contiguous_regions(mask):
38813882
"""
38823883
return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
38833884
True and we cover all such regions
38843885
"""
3885-
mask = np.asarray(mask, dtype=bool)
3886-
3887-
if not mask.size:
3888-
return []
3889-
3890-
# Find the indices of region changes, and correct offset
3891-
idx, = np.nonzero(mask[:-1] != mask[1:])
3892-
idx += 1
3893-
3894-
# List operations are faster for moderately sized arrays
3895-
idx = idx.tolist()
3896-
3897-
# Add first and/or last index if needed
3898-
if mask[0]:
3899-
idx = [0] + idx
3900-
if mask[-1]:
3901-
idx.append(len(mask))
3902-
3903-
return list(zip(idx[::2], idx[1::2]))
3886+
return cbook.contiguous_regions(mask)
39043887

39053888

39063889
@cbook.deprecated("2.2")

0 commit comments

Comments
 (0)