☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Error bars not showing up in Bar

Community Support
Kasia_Rachuta
Kasia_Rachuta

I’m plotting a Bar chart and I want to add error bars. I have used this: http://stackoverflow.com/questions/29166353/how-do-you-add-error-bars-to-bokeh-plots-in-python

but for some reason, despite adding the code below, I’m still not getting the error bars to show up. The Bar chart shows up as expected. Please advise. I’m not including my DataFrame to preserve confidentiality but I could perhaps erase some of the entries if that would make things easier.

p = Bar(all_contracts, values=‘%_saved’, label=‘contract_type’, plot_width=450, plot_height=450,

ylabel = ‘Percentage saved’, xlabel = ‘Contract type’, tools=False, outline_line_alpha=0, line_color=‘white’,

notebook=True, color=‘grey’, fill_alpha=0.3)

p.legend.location = None

p.xgrid.grid_line_color = None

p.ygrid.grid_line_color = None

p.xaxis.major_tick_in = 0

p.xaxis.major_tick_out = 0

p.axis.minor_tick_in = 0

p.axis.minor_tick_out = 0

ys = all_contracts[‘%_saved’]

xs = all_contracts[‘contract_type’]

create the coordinates for the errorbars

err_xs =

err_ys =

for x, y, yerr in zip(xs, ys, yerrs): # Also took out yerr from this line but that didn’t help much.

err_xs.append((x, x))

err_ys.append((all_contracts[‘lower_ci’], all_contracts[‘upper_ci’]))

plot them

p.multi_line(err_xs, err_ys, color=‘red’)

show(p)

⌁   Link to post
Tyler_Nickerson
Tyler_Nickerson

It looks like the issue is in the last line of this for loop.

for x, y, yerr in zip(xs, ys, yerrs): err_xs.append((x, x))
err_ys.append((all_contracts['lower_ci'], all_contracts['upper_ci']))

If you inspect err_xs it should look something like this:

[(xs[1], xs[1]), (xs[2], xs[2]), ..., (xs[n], xs[n])]

err_ys on the other hand should look something like:

[(all_contracts['lower_ci'], all_contract['upper_ci']), (all_contracts['lower_ci'], all_contracts['upper_ci']), ..., (all_contracts['lower_ci'], all_contracst['upper_ci'])]

This is likely not what you wanted. Try something like this instead:

ys = all_contracts['%_saved']
xs = all_contracts['contract_type']
err_hi = all_contracts['upper_ci']
err_lo = all_contracts['lower_ci'
]
# create the coordinates for the errorbars
err_xs = []
err_ys = []
for x, y, erl, erh in zip(xs, ys, err_lo, err_hi):
# this didn't work with lists of tuples for me,
    # I changed them to lists of lists.. ymmv
    err_xs.append([x, x])
err_ys.append([erl, erh])

​

···

On Mon, Apr 17, 2017 at 3:38 PM, Kasia Rachuta korachuta@gmail.com wrote:

I’m plotting a Bar chart and I want to add error bars. I have used this: http://stackoverflow.com/questions/29166353/how-do-you-add-error-bars-to-bokeh-plots-in-python

but for some reason, despite adding the code below, I’m still not getting the error bars to show up. The Bar chart shows up as expected. Please advise. I’m not including my DataFrame to preserve confidentiality but I could perhaps erase some of the entries if that would make things easier.

p = Bar(all_contracts, values=‘%_saved’, label=‘contract_type’, plot_width=450, plot_height=450,

ylabel = ‘Percentage saved’, xlabel = ‘Contract type’, tools=False, outline_line_alpha=0, line_color=‘white’,

notebook=True, color=‘grey’, fill_alpha=0.3)

p.legend.location = None

p.xgrid.grid_line_color = None

p.ygrid.grid_line_color = None

p.xaxis.major_tick_in = 0

p.xaxis.major_tick_out = 0

p.axis.minor_tick_in = 0

p.axis.minor_tick_out = 0

ys = all_contracts[‘%_saved’]

xs = all_contracts[‘contract_type’]

create the coordinates for the errorbars

err_xs =

err_ys =

for x, y, yerr in zip(xs, ys, yerrs): # Also took out yerr from this line but that didn’t help much.

err_xs.append((x, x))

err_ys.append((all_contracts[‘lower_ci’], all_contracts[‘upper_ci’]))

plot them

p.multi_line(err_xs, err_ys, color=‘red’)

show(p)

–

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5fd6ac80-9a91-4293-8b2e-5843b3dea771%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post

End of archived discussion · Replies are disabled