# How to get a coordinates of the square in a heatmap using Observables?

**URL:** <https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573>\
**Category:** Visualization\
**Tags:** makie, observables\
**Created:** [April 5, 2024, 3:47pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573 "2024-04-05T15:47:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [April 5, 2024, 3:47pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573/1 "2024-04-05T15:47:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [April 5, 2024, 4:05pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573/2 "2024-04-05T16:05:50Z")

</div>

Assuming this is in Makie 😃 - in that case, check out the [events explanation in the docs](https://docs.makie.org/dev/explanations/events/#mouse_interaction)! 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.

---

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [April 8, 2024, 1:16pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573/3 "2024-04-08T13:16:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [April 8, 2024, 1:42pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573/4 "2024-04-08T13:42:03Z")

</div>

Gosh, there is no even documentation for `Makie.project`…

---

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [April 24, 2024, 4:05pm UTC](https://discourse.julialang.org/t/how-to-get-a-coordinates-of-the-square-in-a-heatmap-using-observables/112573/5 "2024-04-24T16:05:49Z")

</div>

How I solved it:

```julia
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]

```
