Skip to content

Commit 471100f

Browse files
committed
Mask invalid entries in weights as well, and use cbook.safe_masked_invalid instead of np.ma.masked_invalid.
1 parent 71f3ef3 commit 471100f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/matplotlib/axes/_axes.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,7 @@ def _normalize_input(inp, ename='input'):
60556055
if (isinstance(x, np.ndarray) or
60566056
not iterable(cbook.safe_first_element(inp))):
60576057

6058-
inp = np.asarray(inp)
6058+
inp = cbook.safe_masked_invalid(inp)
60596059
if inp.ndim == 2:
60606060
# 2-D input with columns as datasets; switch to rows
60616061
inp = inp.T
@@ -6077,7 +6077,7 @@ def _normalize_input(inp, ename='input'):
60776077
"{ename} must be 1D or 2D".format(ename=ename))
60786078
else:
60796079
# Change to a list of arrays
6080-
inp = [np.asarray(arr) for arr in inp]
6080+
inp = [cbook.safe_masked_invalid(arr) for arr in inp]
60816081

60826082
return inp
60836083

@@ -6138,24 +6138,25 @@ def _normalize_input(inp, ename='input'):
61386138
else:
61396139
w = _normalize_input(weights, 'weights')
61406140

6141+
# Comparing shape of weights vs. x
61416142
if len(w) != nx:
61426143
raise ValueError('weights should have the same shape as x')
61436144

6144-
# Masking invalid data:
6145-
# Where an element of x[i] is invalid (NaN or inf), it and the
6146-
# corresponding element of weights[i] (if weights used) will be masked.
6147-
for i in range(len(x)):
6148-
xi_mask = np.ma.masked_invalid(x[i]).mask
6149-
x[i] = np.ma.masked_array(x[i], mask=xi_mask).compressed()
6150-
if weights[i]:
6151-
weights[i] = np.ma.masked_array(
6152-
weights[i], mask=xi_mask).compressed()
6153-
61546145
for xi, wi in zip(x, w):
61556146
if wi is not None and len(wi) != len(xi):
61566147
raise ValueError(
61576148
'weights should have the same shape as x')
61586149

6150+
# Combine the masks from x[i] and w[i] (if applicable) into a single
6151+
# mask and apply it to both.
6152+
if not input_empty:
6153+
for i in range(len(x)):
6154+
mask_i = x[i].mask
6155+
if w[i] is not None:
6156+
mask_i = mask_i | w[i].mask
6157+
w[i] = np.ma.masked_array(w[i], mask=mask_i).compressed()
6158+
x[i] = np.ma.masked_array(x[i], mask=mask_i).compressed()
6159+
61596160
if color is None:
61606161
color = [self._get_lines.get_next_color() for i in xrange(nx)]
61616162
else:

0 commit comments

Comments
 (0)