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

Skip to content

Commit 4832bac

Browse files
committed
Merge pull request #1140 from tonysyu/fill_between-fix-nan
BUG: Fix fill_between when NaN values are present
2 parents 086c0a6 + f4e8b58 commit 4832bac

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

lib/matplotlib/axes.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import matplotlib.collections as mcoll
1717
import matplotlib.colors as mcolors
1818
import matplotlib.contour as mcontour
19-
import matplotlib.dates as mdates
2019
from matplotlib import docstring
2120
import matplotlib.font_manager as font_manager
2221
import matplotlib.image as mimage
@@ -6719,9 +6718,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
67196718
self._process_unit_info(ydata=y2)
67206719

67216720
# Convert the arrays so we can work with them
6722-
x = np.asanyarray(self.convert_xunits(x))
6723-
y1 = np.asanyarray(self.convert_yunits(y1))
6724-
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))
67256724

67266725
if y1.ndim == 0:
67276726
y1 = np.ones_like(x)*y1
@@ -6736,14 +6735,12 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
67366735
if not (x.shape == y1.shape == y2.shape == where.shape):
67376736
raise ValueError("Argument dimensions are incompatible")
67386737

6739-
mask = reduce(ma.mask_or,
6740-
[ma.getmask(x), ma.getmask(y1), ma.getmask(y2)])
6738+
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)])
67416739
if mask is not ma.nomask:
67426740
where &= ~mask
67436741

67446742
polys = []
67456743
for ind0, ind1 in mlab.contiguous_regions(where):
6746-
theseverts = []
67476744
xslice = x[ind0:ind1]
67486745
y1slice = y1[ind0:ind1]
67496746
y2slice = y2[ind0:ind1]
@@ -6853,9 +6850,9 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
68536850
self._process_unit_info(xdata=x2)
68546851

68556852
# Convert the arrays so we can work with them
6856-
y = np.asanyarray(self.convert_yunits(y))
6857-
x1 = np.asanyarray(self.convert_xunits(x1))
6858-
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))
68596856

68606857
if x1.ndim == 0:
68616858
x1 = np.ones_like(y)*x1
@@ -6870,14 +6867,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
68706867
if not (y.shape == x1.shape == x2.shape == where.shape):
68716868
raise ValueError("Argument dimensions are incompatible")
68726869

6873-
mask = reduce(ma.mask_or,
6874-
[ma.getmask(y), ma.getmask(x1), ma.getmask(x2)])
6870+
mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)])
68756871
if mask is not ma.nomask:
68766872
where &= ~mask
68776873

68786874
polys = []
68796875
for ind0, ind1 in mlab.contiguous_regions(where):
6880-
theseverts = []
68816876
yslice = y[ind0:ind1]
68826877
x1slice = x1[ind0:ind1]
68836878
x2slice = x2[ind0:ind1]

0 commit comments

Comments
 (0)