☰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

Convert Mouse coordinates to plot coordinates

Community Supportbokehjs
samr85
samr85

Hi,
Is there any way to convert mouse coordinates to a plot X/Y value? Basically like the tap tool, except I need something a lot more powerful, so having to detect the event myself using JS, and need some way to convert that to the XY values.

In more detail - I want shift click and shift right click to set the plot X min/max and alt click/alt right click to set the plot Y min/max, and the tap tool can neither pass through modifiers, or the right click, and JS events can pick them up trivially. I think that I can get it working by using a hovertool that continuously copies the current XY coordinates into a JS variable, and then the click to read those out, but was wondering if there was a more elegant way to do it.

Many thanks,
Sam

⌁   Link to post
samr85
samr85

Thanks for the suggestion! The only mention I can find of that is a pull request for version 2.2 (A basis for sub-coordinate systems by mattpap · Pull Request #10202 · bokeh/bokeh · GitHub), so I’m guessing it’s not in the release branch yet. Taking that code, and trying to run graph.x_scale.v_invert manually, it gives an error message “this.source_range is null”. I’ve tried doing graph.x_scale.source_range = graph.x_range, (no idea if that’s right!) but then it gives the error message this.target_range is null… So not sure how I should be using that!

⌁   Link to post
samr85
samr85

Thanks! If you take the example from here:

With the minor modification to give the graph a name, then run in the JS console:

Bokeh.documents[0].get_model_by_name(‘line’).x_scale.v_invert(123)

⌁   Link to post
p-himik
p-himik

Mmm, right. Seems like the attributes are set, but only within CartesianFrame. An instance of which is available in PlotView, but the view itself is not a very accessible structure.

⌁   Link to post
samr85
samr85

By just playing around, I can’t find any way to get hold of the instance of the view in the JS console - I’ve not touched views before, so don’t know how I should use them (if I even should!). I can go through the renderer to get a view, but I think that’s the data source view, rather than the plot view, and I can’t work out a way to go ‘up’. This feels like I’m going into stuff that isn’t designed for users to use and might be changed on newer versions, so maybe better to stick with my hack.

⌁   Link to post
p-himik
p-himik

This feels like I’m going into stuff that isn’t designed for users to use and might be changed on newer versions

That is absolutely the case since none of this stuff is documented.

⌁   Link to post

End of archived discussion · Replies are disabled