☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Selection of Region Of Interest (ROI) on a heatmap

Community Support
stamljf
stamljf

The following code works to create an interactive heatmap (movable/zoomable).

How to add the possibility of doing a selection rectangle (“Region Of Interest”, ROI), that will stay displayed?

If we use the icon “selection+magnification glass”, it works with a drag and drop, but after releasing the mouse, it automatically zooms in the selection.

Instead, I would like to keep the selection rectangle displayed, but not zoom in it : just keep the selection rectangle visible as a ROI (Region Of Interest) of the bigger image.

How to do that?

image

import numpy as np
import bokeh.models, bokeh.plotting, bokeh.embed, bokeh.models.callbacks, bokeh.models, bokeh.layouts
Z = np.random.randn(100, 100)
color_mapper = bokeh.models.LinearColorMapper(palette="Viridis256", low=0, high=5)
plot = bokeh.plotting.figure(x_range=(0, 1), y_range=(0, 1), height=200)
plot.image(image=[Z], color_mapper=color_mapper, dh=1.0, dw=1.0, x=0, y=0)
color_bar = bokeh.models.ColorBar(color_mapper=color_mapper)
plot.add_layout(color_bar, "right")
bokeh.plotting.show(plot)
⌁   Link to post
stamljf
stamljf

Thanks @mateusz and @Bryan for your answers! Your link SelectionGeometry example looks like a good solution for now! Would you know how to allow only one selection rectangle?

i.e. when the user does a second selection rectangle, it replaces the previous one.

This would be perfect :slight_smile:


(PS: would you have an idea for Bokeh: how to update/redraw the plot data after slider.on_change (with AJAX)?? TL;DR I already have a Flask server for the rest of the application and I would like to keep this server and use AJAX to refresh/update the plots.)

⌁   Link to post
Bryan
Bryan

Would you know how to allow only one selection rectangle?

Omit the concat with the old data:

    source.data = {
        left: [geometry.x0],
        right: [geometry.x1],
        top: [geometry.y0],
        bottom: [geometry.y1]
    }
⌁   Link to post
stamljf
stamljf

With the SelectionGeometry tool, we cannot move or resize the rectangle selection box after the selection has been made, is that correct ?

@mateusz With your pull request Editable annotations and persistent selection overlays by mattpap · Pull Request #12468 · bokeh/bokeh · GitHub both moving and resizing seem to be available. Will this feature be available in BokehJS (without Python)?
Would you have the example code that allowed you to record the screencast? I’d like to test this new feature :slight_smile:

⌁   Link to post
mateusz
mateusz

With the SelectionGeometry tool, we cannot move or resize the rectangle selection box after the selection has been made, is that correct?

Yes, you would have implement this yourself, but this is precisely what my PR is trying to achieve.

(…) both moving and resizing seem to be available. Will this feature be available in BokehJS (without Python)?

Functionality of bokeh (Python) and bokehjs is mirrored as much as possible, so yes it will be available.

Would you have the example code that allowed you to record the screencast? I’d like to test this new feature

In the PR, there is new examples/interaction/tools/persistent_selection.py example, however it is tailored to selection tools. Other uses are still work in progress, so no examples thus far.

⌁   Link to post
Bryan
Bryan

@stamljf Since this is a new feature, it will go in a 3.1 release. The next planned release will be in January, but it may be a 3.0.x bugfix release if the 3.1 branch is not ready then.

With the SelectionGeometry tool, we cannot move or resize the rectangle selection box after the selection has been made, is that correct ?

As @mateusz mentioned, that is not correct, but the updates have to be done manually, at present. Here is a relevant example:

JavaScript callbacks — Bokeh 3.3.2 Documentation

⌁   Link to post

End of archived discussion · Replies are disabled