Skip to content

[BUG] Boxplot draws whiskers above/below max/min values. #720

Open

Description

@your-diary

Describe the bug

According to Box plot - Wikipedia (emphasis mine):

The whiskers must end at an observed data point, but can be defined in various ways.

In the most straightforward method, the boundary of the lower whisker is the minimum value of the data set, and the boundary of the upper whisker is the maximum value of the data set.

(snip)

Another popular choice for the boundaries of the whiskers is based on the 1.5 IQR value. From above the upper quartile (Q3), a distance of 1.5 times the IQR is measured out and a whisker is drawn up to the largest observed data point from the dataset that falls within this distance. Similarly, a distance of 1.5 times the IQR is measured out below the lower quartile (Q1) and a whisker is drawn down to the lowest observed data point from the dataset that falls within this distance. Because the whiskers must end at an observed data point, the whisker lengths can look unequal, even though 1.5 IQR is the same for both sides.

Boxplot seems not to follow this rule:

  • Actual: Boxplot just plots lower/upper fences.

  • Expected: it should instead plot max(min_value, lower_fence) and min(max_value, upper_fence).

To Reproduce

The problem is reproduced by (but not limited to) the official example for boxplot.

Image

Version Information

0.3.7

Activity

  1. nielsle commented on Feb 2, 2026

    @nielsle

    I am no a maintainer, but for future reference the relevant code is here

    https://github.com/plotters-rs/plotters/blob/master/plotters/src/data/quartiles.rs#L50-L55

    The code calculates the lower fence correctly, but it needs to distinguish between "lower fence" and "left whisker position"

    • If there are no outliers then he position of the left whisker should be the smallest datapoint
    • If there are outliers then he position of the left whisker should be the the lower fence (as in the code)

    (Furthermore he median is usually the average of the two center datapoints if the number of datapoints are equal)

  2. nielsle commented on Feb 2, 2026

    @nielsle

    The following old version has the correct median, but the wrong position of left whiskers
    https://github.com/plotters-rs/plotters/blob/298862ee4d76debc275d12e59b2fe25ea33f5373/src/data/quartiles.rs

  3. hunxjunedo commented on Feb 7, 2026

    @hunxjunedo

    @AaronErhardt I'd like to work on this, mind assigning ?

  4. nielsle commented on Feb 8, 2026

    @nielsle

    I don´t think that you have to wait for Aaron. I can almost guarantee that nobody is working on this.

  5. hunxjunedo commented on Feb 8, 2026

    @hunxjunedo

    I can raise a PR but not sure if anyone from the team will review it.

  6. hunxjunedo commented on Feb 9, 2026

    @hunxjunedo

    @nielsle don't you think in case of an outlier the whisper should be at the smallest actual data-point within fences ? Because that seems to be the standard, or are you sure that whisper should be at the fence (not an actual datapoint) ?

  7. nielsle commented on Feb 10, 2026

    @nielsle

    Hmm.. you are right.

    By the way #237 has some prior work on box-plots, but I think that you need to contact the author if you want to borrow code....

  8. hunxjunedo commented on Jul 17, 2026

    @hunxjunedo

    @nielsle @your-diary sorry for the delay guys, completely forgot this one.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions