How to update the palette of a color bar?

I’m trying to change the color palette of a color bar using a callback but nothing happens.
Here’s a minimal working example:

from bokeh.models.mappers import LinearColorMapper
from bokeh.plotting import figure
from bokeh.palettes import Viridis256, Cividis256
from bokeh.models import ColorBar, Button, Column
from bokeh.io import curdoc

# Create a button and a plot
btn = Button(label="click")
f = figure()
f.circle(x=[1, 2, 3], y=[2, 4, 6])

# Add a color bar to the right side of the plot
mapper = LinearColorMapper(palette=Viridis256, low=1, high=10 ^ 4)
color_bar = ColorBar(color_mapper=mapper, location=(0, 0))
f.add_layout(color_bar, "right")

# Button's "on_click" callback
def on_click(event):
    f.right[0].color_mapper.palette = Cividis256


btn.on_click(on_click)

curdoc().add_root(Column(btn, f))

Glancing at the source code, I don’t see any event handling plumbing that would respond to a change on the mapper. That means the configuration is only an initial configuration. You would need to make a GitHub Issue to request this as a feature and wait for new development. In the mean time your best option is probably to make multiple colorbars up front and toggle their visibility as appropriate.

1 Like

@Bryan Thanks, I’ve created a Github issue.