
I have a Parameterized class which is going to create an interactive Bokeh contour plot, using image() function. A colorbar is associated to the contour data, using a LinearColorMapper. This is a sample of the code to create the plot:
# these are 2D numpy arrays. `s` is a custom object
x, y, z = s.get_data()
x, y, zz = [t.flatten() for t in [x, y, z]]
minx, miny, minz = min(x), min(y), min(zz)
maxx, maxy, maxz = max(x), max(y), max(zz)
fig.image(image=[z], x=minx, y=miny,
dw=abs(maxx - minx), dh=abs(maxy - miny),
palette=colormap)
colormapper = LinearColorMapper(palette=colormap, low=minz, high=maxz)
colorbar = ColorBar(color_mapper=colormapper, title="test")
fig.add_layout(colorbar, 'right')
The following is a sample of the code to update the data:
x, y, z = s.get_data()
fig.renderers[0].data_source.data.update({"image": [z]})
zz = z.flatten()
colorbar.color_mapper.update(low = min(zz), high=max(zz))
At this point:
- the contour plot gets updated correctly.
- the values of the color mapper gets updated correctly. If I print them on the screen, I see the updated values.
- the colorbar doesn’t update. It’s like its not being rendered with the new values.
What can I do to fix the problem?