Skip to content

Commit a537aaa

Browse files
committed
Remove invalid data before plotting histograms.
1 parent 1d9783b commit a537aaa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6142,6 +6142,16 @@ def _normalize_input(inp, ename='input'):
61426142
if len(w) != nx:
61436143
raise ValueError('weights should have the same shape as x')
61446144

6145+
# Masking invalid data:
6146+
# Where an element of x[i] is invalid (NaN or inf), it and the
6147+
# corresponding element of weights[i] (if weights used) will be masked.
6148+
for i in range(len(x)):
6149+
xi_mask = np.ma.masked_invalid(x[i]).mask
6150+
x[i] = np.ma.masked_array(x[i], mask=xi_mask).compressed()
6151+
if weights[i]:
6152+
weights[i] = np.ma.masked_array(
6153+
weights[i], mask=xi_mask).compressed()
6154+
61456155
for xi, wi in zip(x, w):
61466156
if wi is not None and len(wi) != len(xi):
61476157
raise ValueError(

0 commit comments

Comments
 (0)