From 4a882dc920ae0281e2f0be61137807034bc9e052 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Wed, 22 Aug 2012 21:46:09 -0400 Subject: [PATCH 1/3] BUG: Mask nans in fill_between(x) --- lib/matplotlib/axes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index c6115693d38e..a1dd61ab960c 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -6736,8 +6736,8 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, if not (x.shape == y1.shape == y2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - mask = reduce(ma.mask_or, - [ma.getmask(x), ma.getmask(y1), ma.getmask(y2)]) + mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan) + for a in (x, y1, y2)]) if mask is not ma.nomask: where &= ~mask @@ -6870,8 +6870,8 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs): if not (y.shape == x1.shape == x2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - mask = reduce(ma.mask_or, - [ma.getmask(y), ma.getmask(x1), ma.getmask(x2)]) + mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan) + for a in (y, x1, x2)]) if mask is not ma.nomask: where &= ~mask From fd804e054a1e22721de29c9cb5604c27ab810099 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Wed, 22 Aug 2012 21:47:42 -0400 Subject: [PATCH 2/3] STY: Remove unused variables and import. --- lib/matplotlib/axes.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index a1dd61ab960c..92927623075f 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -16,7 +16,6 @@ import matplotlib.collections as mcoll import matplotlib.colors as mcolors import matplotlib.contour as mcontour -import matplotlib.dates as mdates from matplotlib import docstring import matplotlib.font_manager as font_manager import matplotlib.image as mimage @@ -6743,7 +6742,6 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, polys = [] for ind0, ind1 in mlab.contiguous_regions(where): - theseverts = [] xslice = x[ind0:ind1] y1slice = y1[ind0:ind1] y2slice = y2[ind0:ind1] @@ -6877,7 +6875,6 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs): polys = [] for ind0, ind1 in mlab.contiguous_regions(where): - theseverts = [] yslice = y[ind0:ind1] x1slice = x1[ind0:ind1] x2slice = x2[ind0:ind1] From f4e8b58d62bea77c1d8efca0f29d0fea5e080c98 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Fri, 24 Aug 2012 22:12:15 -0400 Subject: [PATCH 3/3] Use np.ma.masked_invalid to mask NaNs. --- lib/matplotlib/axes.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 92927623075f..71bf4ca86a11 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -6718,9 +6718,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, self._process_unit_info(ydata=y2) # Convert the arrays so we can work with them - x = np.asanyarray(self.convert_xunits(x)) - y1 = np.asanyarray(self.convert_yunits(y1)) - y2 = np.asanyarray(self.convert_yunits(y2)) + x = ma.masked_invalid(self.convert_xunits(x)) + y1 = ma.masked_invalid(self.convert_yunits(y1)) + y2 = ma.masked_invalid(self.convert_yunits(y2)) if y1.ndim == 0: y1 = np.ones_like(x)*y1 @@ -6735,8 +6735,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, if not (x.shape == y1.shape == y2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan) - for a in (x, y1, y2)]) + mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)]) if mask is not ma.nomask: where &= ~mask @@ -6851,9 +6850,9 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs): self._process_unit_info(xdata=x2) # Convert the arrays so we can work with them - y = np.asanyarray(self.convert_yunits(y)) - x1 = np.asanyarray(self.convert_xunits(x1)) - x2 = np.asanyarray(self.convert_xunits(x2)) + y = ma.masked_invalid(self.convert_yunits(y)) + x1 = ma.masked_invalid(self.convert_xunits(x1)) + x2 = ma.masked_invalid(self.convert_xunits(x2)) if x1.ndim == 0: x1 = np.ones_like(y)*x1 @@ -6868,8 +6867,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs): if not (y.shape == x1.shape == x2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - mask = reduce(ma.mask_or, [f(a) for f in (ma.getmask, np.isnan) - for a in (y, x1, x2)]) + mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)]) if mask is not ma.nomask: where &= ~mask