I am trying to build a multi-dimensional image viewer using Panel and Bokeh and I would like to provide a slider to modify the scale of the intensities shown on the image.
For this, I would need to modify the color mapper of the Bokeh figure image. I first tried to set the argument color_mapper of fig.image to a string color_mapper so I could set it in a ColumnDataSource but it does not work.
Is that possible to set a new color mapper attached to a Bokeh image? Or even better to modify the high and low parameters (avoiding the unnecessary recreation of the color mapper object).
The same question also applies to the palette used in the ColorMapper . That would be nice to be able to ‘dynamically’ modify it.
Generally, to have the best chance of getting help, it is most effective to provide a code sample, and ideally a minimal complete example of what you have tried. For instance, it’s not clear from your description if this is a standalone HTML scenario (which means only CustomJS could be used) or a Bokeh server app (which means real Python callbacks could be used)
@hadim The color mapper is not something that goes in a ColumnDataSource, so putting it in source.data will never be a correct thing to do. In fact, it is something that manipulates data in a data source. Have you looked at the Transforming Data section of the User’s Guide? That shows how you can use the higher level linear_cmap which is simpler and what I would suggest for most use cases.
Mapping the mapper to a data source was a way to illustrate what I am trying to achieve. As said in my first post I am looking for a way to switch the color mapper of an image after its creation. I want to be able to modify both the high/low values and the colormap itself.
For example, I first create a Bokeh figure then add an image to it with a LinearColorMapper or linear_cmap. Then my plan is to have a slider or a button to allow the user to switch to different colormap and modify the high and low value of the mapper.
Ideally, I would like to modify the already existing Bokeh figure if it’s possible. It if it’s not possible then I would have to recreate the entire Bokeh figure each time.
You can set e.g. my_mapper.high at any time. If you are in a Bokeh server application, you can set it from real Python code. If you have standalone HTML output (i.e. from output_file) then a CustomJS callback could set new property values. In general, views of Bokeh objects (i.e. plots, gylphs, whatever) are automatically reactive to changes set on them.
Ahah I was trying to access the color mapper from within the figure directly without thinking I could just keep track of the mapper instance. Of course it works fine