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

[BUG] Whiskers do not appear in categorical plots? #10575

Closed
lyijin opened this issue Oct 14, 2020 · 6 comments · Fixed by #10577
Closed

[BUG] Whiskers do not appear in categorical plots? #10575

lyijin opened this issue Oct 14, 2020 · 6 comments · Fixed by #10577

Comments

@lyijin
Copy link

lyijin commented Oct 14, 2020

Software version info

OS: Linux 5.6.0-2-amd64 #1 SMP Debian 5.6.14-2 (2020-06-09) x86_64 GNU/Linux
Bokeh version: 2.2.2
Python version: 3.8.6

Description of expected behavior and the observed behavior

I used to be able to combine whiskers into categorical plots using Bokeh 1.4.0. When I upgraded to 2.2.2, the whiskers disappeared. The plot I have in mind is a dotplot + whiskers + multi-category plot, with the (single) dot indicating the mean and whiskers as stderr.

Complete, minimal, self-contained example code that reproduces the issue

(this code is lightly edited from https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html?highlight=whisker, and incorporates some categorical code (e.g. x_range=FactorRange(*x)) from https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html.

from bokeh.models import ColumnDataSource, Whisker, FactorRange
from bokeh.plotting import output_file, figure, show, save
from bokeh.sampledata.autompg import autompg as df

output_file('whiskers.html')

colors = ["red", "olive", "darkred", "goldenrod", "skyblue", "orange", "salmon"]

base, lower, upper, mpg = [], [], [], []

for i, year in enumerate(list(df.yr.unique())):
    year_mpgs = df[df['yr'] == year]['mpg']
    mpgs_mean = year_mpgs.mean()
    mpgs_std = year_mpgs.std()
    lower.append(mpgs_mean - mpgs_std)
    upper.append(mpgs_mean + mpgs_std)
    mpg.append(mpgs_mean)
    #base.append(str(year))
    base.append((str(year), 'a'))

#p = figure(plot_width=600, plot_height=300, title="Years vs mpg with Quartile Ranges")
p = figure(x_range=FactorRange(*base), plot_width=600, plot_height=300, title="Years vs mpg with Quartile Ranges")
source_error = ColumnDataSource(data=dict(base=base, lower=lower, upper=upper, mpg=mpg))
p.scatter(x='base', y='mpg', source=source_error)

p.add_layout(
    Whisker(source=source_error, base="base", upper="upper", lower="lower")
)

save(p)

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

When the code is run as provided above, this is what I got.
bokeh_plot (1)

When the commented statements are uncommented (i.e. #base.append(str(year)) and #p = figure(plot_width=600, plot_height=300, title="Years vs mpg with Quartile Ranges")), and the line following that is commented out, I get
bokeh_plot (2)

Not exactly sure what's wrong, but it seems to me that Whisker seem to only appear on numerical-type axis, not a factorial-type one? Thanks for looking into this!

@mattpap
Copy link
Contributor

mattpap commented Oct 14, 2020

Currently most annotations are limited to numerical axes, though it should be pretty simple to lift this restriction in Whisker's case.

@alucab
Copy link

alucab commented Jan 5, 2021

Hello any workaround to have whiskers on 2.2.3 ?
I would love to use Bokeh in my next application, the code is quite cleaner than Dash and the embedding is waaaay easier.

But i need grouped Bar Charts with error bars :-(

Thanks for any help

@bryevdv
Copy link
Member

bryevdv commented Jan 5, 2021

@alucab the fix for this is merged and will be in the upcoming 2.3.0 release

@alucab
Copy link

alucab commented Jan 5, 2021 via email

@ghomem
Copy link

ghomem commented Sep 14, 2021

Happened to me on the update from 2.0.2 to 2.2.0. Fixed with 2.3.0.

Copy link

This issue 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 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants