FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Boxplot - wrong median · Issue #184 · matplotlib/matplotlib · GitHub

Repository navigation

Boxplot - wrong median #184

Closed
Closed

Description

Original report at SourceForge, opened Tue Jan 4 04:52:13 2011

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.

How to reproduce:

example data

d = array([ 13., 9., 16., 8., 7., 14., 15., 5., 10., 16., 8., 15., 14., 19., 10., 10.], dtype=float32)
q1, med, q3 = mlab.prctile(d,[25,50,75]) # axes.py line 5005 axes.py (0.99.3 Rev 8345)
med_default = median(d) # for comparison
print((med,med_default)) # med = 13.0 med_default = 11.5

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.

On Tue Jan 4 05:03:55 2011, jmdb wrote:

Seems like this is also discussed here: http://permalink.gmane.org/gmane.comp.python.matplotlib.general/25835

I can add that the median function agrees with f.ex. matlab while the prctile function gives different results.

Activity

  1. 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.

  2. pelson commented on Jun 18, 2012

    Member

    Agreed. Confirm fixed (on master at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL