Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
When I try to boxplot several np.arrays of masked values, ax.boxplot includes the masked values. This throws off the analysis of the data and gives me an almost unusable boxplot.
Bug summary
I masked several -9999 values (equipment error values) in order to look at the variances in the rest of our good data (range between 0~500). I masked the -9999 values using a np.ma.masked_less to give an array of good data with several masked values in the array. Once I called these data into the boxplot, it included the masked -9999 values. I patched this bug by switching out the masked_less call with an inequality statement that replaced the -9999 values with erroneous values (i.e. swapped out -9999 with a random number instead of removing it from the data set).
Boxplot function including masked values in a np.array where it should be ignoring said masked values.
Code for reproduction
# Paste your code here##importnumpyasnpimportmatplotlib.pyplotasplta=np.ma.array([229.5,374.0,536.5,-9999,-9999,-9999,-9999,-9999,182.0,42.5,49.0])b=np.ma.array([363.0,118.5,159.0,-9999,311.0,516.0,380.0,338.5,223.0,211.5,128.5])c=np.ma.array([205.5,277.5,141.5,278.0,302.0,251.0,299.0,250.0,315.5,92.1,211.9])a=np.ma.masked_less(a,-9000 )b=np.ma.masked_less(b,-9000 )c=np.ma.masked_less(c,-9000 )data_to_plot= [a ,b,c ]labels= ['a','c','c' ]fig=plt.figure(3,figsize= (8,10 ) )ax=fig.add_subplot(111,frameon=False )bp=ax.boxplot(data_to_plot,patch_artist=True,widths=.85,labels=labels,vert=True)plt.setp(bp['boxes' ],color='black',alpha=.8,linewidth=3 )plt.setp(bp['whiskers' ],color='black',linewidth=3 )plt.setp(bp['fliers' ],markeredgecolor='black',alpha=1,markersize=30,marker='.' )plt.setp(bp['medians' ],color='orange',linewidth=3 )plt.setp(bp['means' ],color='black' )plt.setp(bp['caps' ],color='black',linewidth=4 )colors= ['r','b','g', ]forbin (bp ):forpatch,colorinzip(bp['boxes' ],colors ):patch.set_facecolor(color )plt.show()
Actual outcome
# If applicable, paste the console output here##
Expected outcome
Expected a boxplot with masked values ignored so only shows unmasked values above -9000
Matplotlib version
- Operating system: macOS High Sierra 10.13.6
- Matplotlib version: 2.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: 3.6
- Jupyter version (if applicable):
- Other libraries: Spyder 3.1.2
Unsure how installed. Think it was through pip