Box plot and missing data (NaN/Masked)


I am trying to plot some arrays with missing data, noted as -9999.9. I have
tried setting these values to NaN and using numpy masked arrays. Neither
produces the correct plot when using box plot. Any suggestions?


import matplotlib.pyplot as plt
import numpy as np

# works fine
y = np.array([568., 576., 436.])
plt.boxplot(y, notch=0, sym='+', vert=1, whis=1.5)

# same array, but with some missing data
x = np.array([-9999.9, 568., -9999.9, -9999.9, 576., -9999.9, 436.])

# mark missing data
xx = np.where(x < -9000.0, np.nan, x)

# try and plot that, nope.
plt.boxplot(xx, notch=0, sym='+', vert=1, whis=1.5)

# mask the array, plot that?
xxx =, mask=np.isnan(xx))
plt.boxplot(xxx, notch=0, sym='+', vert=1, whis=1.5)




View this message in context:
Sent from the matplotlib - users mailing list archive at