Skip to content

Commit bf8d2cc

Browse files
committed
Mask invalid entries in x and weights before plotting histograms.
1 parent b16144f commit bf8d2cc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 additions & 2 deletions
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,6 +6138,7 @@ 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

@@ -6146,6 +6147,16 @@ def _normalize_input(inp, ename='input'):
61466147
raise ValueError(
61476148
'weights should have the same shape as x')
61486149

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+
61496160
if color is None:
61506161
color = [self._get_lines.get_next_color() for i in xrange(nx)]
61516162
else:

0 commit comments

Comments
 (0)