☰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

Customize colors on bar plots

Community Support
carolyn
carolyn

Hi blockhart!

There are a few ways you could do this, depending upon what makes that bar special. Here’s a simple example based on value-- if you literally want only one specific bar to be a different color, maybe you want to go by index position?

from bokeh.plotting import figure, show

x = ['a', 'b', 'c', 'd', 'e', 'f']
num_list = [4, 3, 5, 4, 9, 4]

# construct a list of colors based on characteristics of the values in num_list.
color_list = []
for i in num_list:
    if i > 7:
        color_list.append('orange')
    else:
        color_list.append('blue')

p = figure(x_range=x, plot_height=350, title="vbar color demo",
           toolbar_location=None, tools="")
p.vbar(x=x, top=num_list, color=color_list, width=.9)

show(p)
⌁   Link to post
carolyn
carolyn

Since it looks like VBar takes only a single value as color, any workarounds I’m thinking of would probably be ungainly and cause maintenance issues-- like splitting your data source into two data sources, and then having two different colored glyphs. That would either break or multiply some other things like hover tools, though, and it doesn’t feel like the right way to go.

If it were me, I’d rework to use vbar, unless there’s some other advantage to VBar. I’d love to hear from others in case there’s an approach I’m not thinking of, though.

⌁   Link to post
Bryan
Bryan

The glyph methods (e.g. vbar) are a convenience API built on top of the low-level glyph classes (e.g. VBar) There’s nothing you can do with one that you can’t do with the other, but using the low-level classes will be more work and more verbose, which is why I generally recommend folks to use the glyph methods on figure unless there is a specific reason not to.

To use the VBar, you need to:

  • Create a ColumnDataSource with the data columns you want (x, y, colors, etc)
  • Configure the a VBar instance to refer to those column names
  • Explicity add the glyph and the data source together to a plot with add_glyph(...)

There are lots of examples of these steps in the scripts in the examples/models directory.

⌁   Link to post

End of archived discussion · Replies are disabled