I have an image (or heatmap) and I want to be able to click and find x and y indexes of clicked area using Observables. How could it be possible?
Assuming this is in Makie - in that case, check out the events explanation in the docs! Basically you would lift on axis.scene.events.mousebutton
, and check the value of axis.scene.events.mouseposition
. This is in pixels, but you can project it to data space using Makie.project(axis.scene, :pixel, :data, axis.scene.events.mouseposition[])
or so.
1 Like
First part worked, thanks you!
Second part worked with:
test = Makie.project(camera(ax.scene), :pixel, :data, ax.scene.events.mouseposition[])
But! The coordinates are not correct, unfortunately.
Moreover:
- They update even when I press on white area of the figure, while they obliviously should update only when I press the heatmap area.
- They are float, not numeric
- The ranges do not correspond
Gosh, there is no even documentation for Makie.project
…
How I solved it:
plot, _ = pick(ax.scene)
pos = Makie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
b = Makie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
chan_i[], var_i[] = b[1], b[2]