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

Skip to content

Commit 22cc5c1

Browse files
committed
Broadcast in fill_between{,x} as well.
Also fixes a bug in fill_between with masked data. In the modified test figures, the area in green is supposed to correspond to the part of the hatched area where the curve is below y=2. The new behavior is the correct one.
1 parent 93e3258 commit 22cc5c1

File tree

4 files changed

+90
-112
lines changed

4 files changed

+90
-112
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,22 +4667,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
46674667
raise ValueError('Input passed into argument "%r"' % name +
46684668
'is not 1-dimensional.')
46694669

4670-
if y1.ndim == 0:
4671-
y1 = np.ones_like(x) * y1
4672-
if y2.ndim == 0:
4673-
y2 = np.ones_like(x) * y2
4674-
46754670
if where is None:
4676-
where = np.ones(len(x), np.bool)
4677-
else:
4678-
where = np.asarray(where, np.bool)
4679-
4680-
if not (x.shape == y1.shape == y2.shape == where.shape):
4681-
raise ValueError("Argument dimensions are incompatible")
4671+
where = True
4672+
where = where & ~reduce(np.logical_or, map(np.ma.getmask, [x, y1, y2]))
46824673

4683-
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)])
4684-
if mask is not ma.nomask:
4685-
where &= ~mask
4674+
x, y1, y2 = np.broadcast_arrays(np.atleast_1d(x), y1, y2)
46864675

46874676
polys = []
46884677
for ind0, ind1 in mlab.contiguous_regions(where):
@@ -4828,22 +4817,11 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
48284817
raise ValueError('Input passed into argument "%r"' % name +
48294818
'is not 1-dimensional.')
48304819

4831-
if x1.ndim == 0:
4832-
x1 = np.ones_like(y) * x1
4833-
if x2.ndim == 0:
4834-
x2 = np.ones_like(y) * x2
4835-
48364820
if where is None:
4837-
where = np.ones(len(y), np.bool)
4838-
else:
4839-
where = np.asarray(where, np.bool)
4840-
4841-
if not (y.shape == x1.shape == x2.shape == where.shape):
4842-
raise ValueError("Argument dimensions are incompatible")
4821+
where = True
4822+
where = where & ~reduce(np.logical_or, map(np.ma.getmask, [y, x1, x2]))
48434823

4844-
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)])
4845-
if mask is not ma.nomask:
4846-
where &= ~mask
4824+
y, x1, x2 = np.broadcast_arrays(np.atleast_1d(y), x1, x2)
48474825

48484826
polys = []
48494827
for ind0, ind1 in mlab.contiguous_regions(where):
Binary file not shown.

0 commit comments

Comments
 (0)