Я показываю разные 2D-массивы на графике изображения. Я добавил дополнительно color_mapper и colorbar. Пользователь имеет возможность изменить изображение, выбрав из виджета выбора. Это прекрасно работает, но color_mapper и, следовательно, color_bar не настроены на новое изображение / массив.
Позвольте показать вам код, иллюстрирующий мою проблему:
def callback(attr, old, new):
dict_arrays = dict("array_a" = array_a,
"array_b" = array_b)
array = dict_arrays[select_widget.value]
# I think at this point i have to adjust the colorbar and
# color_mapper otherwise the colormap of the old plot will
# be applied:
.
.
.
# define new dataset:
source.data = dict(image=[array])
# some data:
dim = 100
array_a = np.random.randtint(0,75,10000).reshape(dim,dim)
array_b = np.random.randtint(25,100,10000).reshape(dim,dim)
# find out the max and min of that array:
vmax = np.nanmax(array_a)
vmin = np.nanmin(array_a)
#This is my source:
source = ColumnDataSource(data={'image' : [array_a]})
# create the color_mapper:
color_mapper = LinearColorMapper(palette=cc.coolwarm,
low=vmin,
high=vmax)
# create the figure
plot = figure()
# create the plot:
plot.image(image='image', x=0, y=0, dw=100, dh=100,
color_mapper=color_mapper,
source=source)
color_bar = ColorBar(color_mapper=color_mapper,
ticker=BasicTicker(),
location=(0,0),
line_color=None,
label_standoff=12)
plot.add_layout(color_bar, 'right')
# create a select_widget:
select_widget = Select(title="title", value = "array_a",
options = ["array_a", "array_b"])
# on_change callback
select_widget.on_change('value', callback)
# layout:
layout = layout([select_widget, plot])
curdoc().add_root(layout)