I have a object oriented code, with an image. Sometimes the user want’s a log. colormap, sometimes a linear one. Therefore I want to offer a dropdown where the user can select what colorbar to use. However the following minimal example doesn’t change the colormap, but gives me a AttributeError: 'method' object has no attribute 'color_mapper'
from bokeh.plotting import figure, curdoc
from bokeh.models import LinearColorMapper, LogColorMapper, Select
from bokeh.layouts import column
import numpy as np
class Test:
def __init__(self):
image = np.arange(0, 100, 1).reshape(10, 10)
self.figure = figure()
self.lin_cmap = LinearColorMapper(palette="Turbo256", low=0, high=100)
self.log_cmap = LogColorMapper(palette="Turbo256", low=1, high=100)
self.figure.image([image], x=0, y=0, dh=1, dw=1, color_mapper=self.log_cmap)
self.select = Select(title="colormap", value="linear", options=["linear", "log"])
self.select.on_change("value", self.change_cmap)
def change_cmap(self, attr, old, new):
if new == "log":
self.figure.image.color_mapper = self.log_cmap
else:
self.figure.image.color_mapper = self.lin_cmap
def plot(self):
curdoc().add_root(column(self.figure, self.select))
I have also tried other things, like creating self.cmap and assigning that to either the linear or log cmap, but in that case nothing happens.

