# Makie mouse\_in\_scene gives pixel positions

**URL:** <https://discourse.julialang.org/t/makie-mouse-in-scene-gives-pixel-positions/58864>\
**Category:** Modelling & Simulations\
**Created:** [April 8, 2021, 6:04pm UTC](https://discourse.julialang.org/t/makie-mouse-in-scene-gives-pixel-positions/58864 "2021-04-08T18:04:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 8, 2021, 6:04pm UTC](https://discourse.julialang.org/t/makie-mouse-in-scene-gives-pixel-positions/58864/1 "2021-04-08T18:04:03Z")

</div>

Hi,

I don’t understand why the following code doesn’t work. (maybe I an just blind)

```julia

using AbstractPlotting
X = Node( rand(Point2f0, 10) )
fig = Figure(resolution = (1200, 900))
scatter(fig[1,1], X)

scene = fig.scene
mouse_btn = on(scene.events.mousebuttons, weak = true) do buttons
    if ispressed(scene, Mouse.left)
        p = Point2f0( AbstractPlotting.mouse_in_scene(scene)[] )
        X.val[1] = p
        X[] = X[]
        #println(p)
    end
end

fig
#println( AbstractPlotting.mouse_in_scene(fig.scene))

```

I would expect that a mouse click sets the first point of the array `X` to the position of the mouse click.  
But on my computer, the Point `p` seems to be in pixel coordinates?

* * *

Relevant docs: [https://makie.juliaplots.org/stable/abstractplotting\_api.html#AbstractPlotting.mouse\_in\_scene-Tuple{SceneLike}](https://makie.juliaplots.org/stable/abstractplotting_api.html#AbstractPlotting.mouse_in_scene-Tuple%7BSceneLike%7D)

Env:

```julia
Julia Version 1.5.4
Commit 69fcb5745b (2021-03-11 19:13 UTC)       
Platform Info:
  OS: Windows (x86_64-w64-mingw32)

(mouse_interactive) pkg> st
Status `D:\workspace\julia_projects\mouse_interactive\Project.toml`
  [537997a7] AbstractPlotting v0.15.27
  [13f3f980] CairoMakie v0.3.19
  [e9467ef8] GLMakie v0.1.30
  [ee78f7c6] Makie v0.12.0

```

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 8, 2021, 9:16pm UTC](https://discourse.julialang.org/t/makie-mouse-in-scene-gives-pixel-positions/58864/2 "2021-04-08T21:16:46Z")

</div>

Ok, it seems that `fig.scene` is not the correct scene of the scatter plot.  
If I create a scene with `scene = Scene()` and use `mouseposition()` then I get the world coordinates and it works.

Still, I don’t know how to get select the current scene.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 8, 2021, 9:19pm UTC](https://discourse.julialang.org/t/makie-mouse-in-scene-gives-pixel-positions/58864/3 "2021-04-08T21:19:30Z")

</div>

Ok, I found the solution:

```julia

n = 10
X = Node( rand(Point2f0,n) )
fig = Figure( resolution=(500,500))
plt = scatter(fig[1,1], X)

scene = plt.axis.scene
mouse_btn = on(scene.events.mousebuttons, weak = true) do buttons
    if ispressed(scene, Mouse.left)
        p = mouseposition(scene)
        X.val[1] = p
        X[] = X[]
        println(p)
    end
end

fig

```
