You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a strange boxplot that is generated with the following data:
from pylab import boxplot, savefig
bp = boxplot([2.88497, 1.2143, 0.923436, 1.18696])
show()
The boxplot has the non-outlier max below the upper quartile. I plotted the same data using R's boxplot function and it does not exhibit the same behavior. MPL's boxplot is plotting the max value as an outlier (the '+' sign) but then get confused about how to plot the quartiles and non-outlier max. This can be fixed by changing the whisker length to something more than 1.5 (the default) so that the outlier is seen as the max.
I'm not sure if this is a bug or not, but the boxplot doesn't look right to me using the default settings for boxplot(). I am using matplotlib 1.1.0 on Mac OS X 10.7.4.
Thought I would have a look... First thing, there is a difference between R and python/matplotlib regarding quartile calculations. Given the data [1,2,3,4] matplotlib will give 1.75 as the 25th Percentile while R will give 1.5.
The real problem is that of the boxplots generally not being well defined here as there is no data point between the 75th percentile and the maximum whisker length. In fact R will do just the same as matplotlib and draw the whisker to the center point if this happens (ie, here just set range=0.5 for simplicity in R)...
You could add a warning or such, but I think there is no bug as such here, its just the boxplot itself is not well defined for this input data.
Matlab uses the same method as R for the calculation of the precentiles (thinking about it, this definition means that for the usual whisker length the problem cannot arise). In the case of no well defined whiskers (ie. setting the whisker length to 0.5 from 1.5) it will simply not draw one at all, or maybe 0 length... (matplotlib and R draw a bogus one). But its not like matplotlib calculations are wrong I think, just a different definition for the percentiles.
Activity
seberg commentedon Jul 26, 2012
Thought I would have a look... First thing, there is a difference between R and python/matplotlib regarding quartile calculations. Given the data [1,2,3,4] matplotlib will give 1.75 as the 25th Percentile while R will give 1.5.
The real problem is that of the boxplots generally not being well defined here as there is no data point between the 75th percentile and the maximum whisker length. In fact R will do just the same as matplotlib and draw the whisker to the center point if this happens (ie, here just set range=0.5 for simplicity in R)...
You could add a warning or such, but I think there is no bug as such here, its just the boxplot itself is not well defined for this input data.
dmcdougall commentedon Jul 26, 2012
Does Matlab have functionality to produce box plots? If so, what is the output?
seberg commentedon Jul 26, 2012
Matlab uses the same method as R for the calculation of the precentiles (thinking about it, this definition means that for the usual whisker length the problem cannot arise). In the case of no well defined whiskers (ie. setting the whisker length to 0.5 from 1.5) it will simply not draw one at all, or maybe 0 length... (matplotlib and R draw a bogus one). But its not like matplotlib calculations are wrong I think, just a different definition for the percentiles.
tacaswell commentedon Nov 26, 2013
@phobson as long as you are planning to work on box plot this week can you also take a look at this issue?
phobson commentedon Nov 26, 2013
@tacaswell happily :)
mdboom commentedon Jan 27, 2014
@phobson: Is this addressed by #2643?
phobson commentedon Jan 27, 2014
@mdboom
Yes. Passing the OP's array into
matplotlib.cbook.boxplot_stats(whichboxplotnow uses) returns the following:The upper quartile is the same at the upper whisker (which is ok, IMO) and the max values is reported as an outlier above the upper quartile.
I vote to close this.