Skip to content

Commit f4e8b58

Browse files
committed
Use np.ma.masked_invalid to mask NaNs.
1 parent fd804e0 commit f4e8b58

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/matplotlib/axes.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6718,9 +6718,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
67186718
self._process_unit_info(ydata=y2)
67196719

67206720
# Convert the arrays so we can work with them
6721-
x = np.asanyarray(self.convert_xunits(x))
6722-
y1 = np.asanyarray(self.convert_yunits(y1))
6723-
y2 = np.asanyarray(self.convert_yunits(y2))
6721+
x = ma.masked_invalid(self.convert_xunits(x))
6722+
y1 = ma.masked_invalid(self.convert_yunits(y1))
6723+
y2 = ma.masked_invalid(self.convert_yunits(y2))
67246724

67256725
if y1.ndim == 0:
67266726
y1 = np.ones_like(x)*y1
@@ -6735,8 +6735,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
67356735
if not (x.shape == y1.shape == y2.shape == where.shape):
67366736
raise ValueError("Argument dimensions are incompatible")
67376737

6738-
mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan)
6739-
for a in (x, y1, y2)])
6738+
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)])
67406739
if mask is not ma.nomask:
67416740
where &= ~mask
67426741

@@ -6851,9 +6850,9 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
68516850
self._process_unit_info(xdata=x2)
68526851

68536852
# Convert the arrays so we can work with them
6854-
y = np.asanyarray(self.convert_yunits(y))
6855-
x1 = np.asanyarray(self.convert_xunits(x1))
6856-
x2 = np.asanyarray(self.convert_xunits(x2))
6853+
y = ma.masked_invalid(self.convert_yunits(y))
6854+
x1 = ma.masked_invalid(self.convert_xunits(x1))
6855+
x2 = ma.masked_invalid(self.convert_xunits(x2))
68576856

68586857
if x1.ndim == 0:
68596858
x1 = np.ones_like(y)*x1
@@ -6868,8 +6867,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
68686867
if not (y.shape == x1.shape == x2.shape == where.shape):
68696868
raise ValueError("Argument dimensions are incompatible")
68706869

6871-
mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan)
6872-
for a in (y, x1, x2)])
6870+
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)])
68736871
if mask is not ma.nomask:
68746872
where &= ~mask
68756873

0 commit comments

Comments
 (0)