Hello,
I’m having troubles in getting the mouse position in data coordinates from a Makie plot.
Using mouseposition()
seems to return the position in pixel coordinates contrary to what described in the documentation http://makie.juliaplots.org/v0.15.2/documentation/api_reference/index.html#Events. Maybe be related to the function to_world()
.
Here below a MWE, where mouseposition()
returns the same result that mouseposition_px()
and to_world(fig.scene,Point2f(pos_px))
.
What am I doing wrong?
using GLMakie
img = rand(100, 100)
fig = Figure()
ax1 = Axis(fig[1,1])
image!(ax1,img)
on(events(fig.scene).mousebutton, priority = 0) do event
if event.button == Mouse.left
if event.action == Mouse.press
pos = mouseposition(fig.scene)
pos_px = Makie.mouseposition_px(fig.scene)
twpos = to_world(fig.scene,Point2f(pos_px))
println("mouseposition(): $pos, mouseposition_px(): $pos_px, to_world(pos): $twpos")
println()
end
end
return Consume(false)
end
fig