Skip to content

BUG: Fix fill_between when NaN values are present #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6719,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
Expand All @@ -6736,14 +6735,12 @@ 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, [ma.getmask(a) for a in (x, y1, y2)])
if mask is not ma.nomask:
where &= ~mask

polys = []
for ind0, ind1 in mlab.contiguous_regions(where):
theseverts = []
xslice = x[ind0:ind1]
y1slice = y1[ind0:ind1]
y2slice = y2[ind0:ind1]
Expand Down Expand Up @@ -6853,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
Expand All @@ -6870,14 +6867,12 @@ 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, [ma.getmask(a) for a in (y, x1, x2)])
if mask is not ma.nomask:
where &= ~mask

polys = []
for ind0, ind1 in mlab.contiguous_regions(where):
theseverts = []
yslice = y[ind0:ind1]
x1slice = x1[ind0:ind1]
x2slice = x2[ind0:ind1]
Expand Down