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

Skip to content

Commit 4f560f7

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 b4296f4 commit 4f560f7

File tree

4 files changed

+94
-113
lines changed

4 files changed

+94
-113
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
unicode_literals)
33

44
import six
5-
from six.moves import reduce, xrange, zip, zip_longest
5+
from six.moves import xrange, zip, zip_longest
66

77
from collections import Sized
8+
import functools
89
import itertools
910
import math
1011
import warnings
@@ -4714,22 +4715,12 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
47144715
raise ValueError('Input passed into argument "%r"' % name +
47154716
'is not 1-dimensional.')
47164717

4717-
if y1.ndim == 0:
4718-
y1 = np.ones_like(x) * y1
4719-
if y2.ndim == 0:
4720-
y2 = np.ones_like(x) * y2
4721-
47224718
if where is None:
4723-
where = np.ones(len(x), np.bool)
4724-
else:
4725-
where = np.asarray(where, np.bool)
4726-
4727-
if not (x.shape == y1.shape == y2.shape == where.shape):
4728-
raise ValueError("Argument dimensions are incompatible")
4719+
where = True
4720+
where = where & ~functools.reduce(np.logical_or,
4721+
map(np.ma.getmask, [x, y1, y2]))
47294722

4730-
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)])
4731-
if mask is not ma.nomask:
4732-
where &= ~mask
4723+
x, y1, y2 = np.broadcast_arrays(np.atleast_1d(x), y1, y2)
47334724

47344725
polys = []
47354726
for ind0, ind1 in mlab.contiguous_regions(where):
@@ -4875,22 +4866,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
48754866
raise ValueError('Input passed into argument "%r"' % name +
48764867
'is not 1-dimensional.')
48774868

4878-
if x1.ndim == 0:
4879-
x1 = np.ones_like(y) * x1
4880-
if x2.ndim == 0:
4881-
x2 = np.ones_like(y) * x2
4882-
48834869
if where is None:
4884-
where = np.ones(len(y), np.bool)
4885-
else:
4886-
where = np.asarray(where, np.bool)
4887-
4888-
if not (y.shape == x1.shape == x2.shape == where.shape):
4889-
raise ValueError("Argument dimensions are incompatible")
4870+
where = True
4871+
where = where & ~functools.reduce(np.logical_or,
4872+
map(np.ma.getmask, [y, x1, x2]))
48904873

4891-
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)])
4892-
if mask is not ma.nomask:
4893-
where &= ~mask
4874+
y, x1, x2 = np.broadcast_arrays(np.atleast_1d(y), x1, x2)
48944875

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

0 commit comments

Comments
 (0)