If the boxplot is called with a small number of discrete, not unique values it shows a different median value than the median command. I consider this a bug.
In the example I took the line in axes.py where the median value is computed and compare to a median directly computed. In my opinion the boxplot should use the median function to determine the median such that the same value is reported. I think the reason is in the different handling of equal values of prctile and median.
Anyway: Here is how to fix it:
Replace line 5005 with:
q1, q3 = mlab.prctile(d,[25,75])
And add a new line directly after it (new 5006):
med = np.median(d)
SourceForge Comments
On Thu Jan 13 04:42:32 2011, jmdb wrote:
And to add another point: matlab reports 8.5 for q1.
On Thu Jan 13 04:37:33 2011, jmdb wrote:
In addition: if one also computes:
from scipy import stats
stats.scoreatpercentile(d,25)
results in 8.75 while q1 from the example (which should be the same) is 9.0
I think either the mlab.prctle function should be fixed or be replaced by the function from the stats package.
Activity
jomade commented on Jan 30, 2012
Issue is no longer present in matplotlib 1.1.0
However one should consider to replace the mlab.prctile function with a wrapper around numpy.percentile to avoid unnecessary code duplication.
I propose to close the issue.
pelson commented on Jun 18, 2012
Agreed. Confirm fixed (on master at least).