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))