Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for inward pointing whiskers for some box plots #4548

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

justinbois
Copy link
Contributor

For the Bokeh rendering of box plots, we have been using this definition of a whisker: the maximal data point less than (1.5 times the interquartile region plus the position of the top of the box). With this definition, we can get some strange results, as shown below.

import holoviews as hv
hv.extension('bokeh')

# Box-whisker with transparent box so we can see inward whisker
hv.BoxWhisker(
    data=[1, 2, 3, 10]
).opts(
    box_fill_alpha=0
)

Screen Shot 2020-08-10 at 23 17 12

We see that the top whisker is below the top of the box. This is because we are using the above definition of the whisker position. In the case shown above, the end point of the top whisker is 3, but the top of the box is at 4.75. The description on Wikipedia gives a more precise definition of the whisker:

From above the upper quartile, a distance of 1.5 times the IQR is measured out and a whisker is drawn up to the largest observed point from the dataset that falls within this distance.

To implement this, we can adjust the _box_stats() function in plotting/bokeh/stats.py to define the upper and lower whiskers as follows.

            upper = max(vals[vals <= q3 + 1.5*iqr].max(), q3)
            lower = min(vals[vals >= q1 - 1.5*iqr].min(), q1)

@philippjfr
Copy link
Member

Thanks @justinbois! The changes make sense, merging.

@philippjfr philippjfr merged commit 3d07924 into holoviz:master Aug 14, 2020
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants