# How to correctly pick the index of heatmap cell?

**URL:** <https://discourse.julialang.org/t/how-to-correctly-pick-the-index-of-heatmap-cell/113230>\
**Category:** Visualization\
**Created:** [April 19, 2024, 10:38am UTC](https://discourse.julialang.org/t/how-to-correctly-pick-the-index-of-heatmap-cell/113230 "2024-04-19T10:38:42Z")\
**Posts on this page:** 3\
**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 19, 2024, 10:38am UTC](https://discourse.julialang.org/t/how-to-correctly-pick-the-index-of-heatmap-cell/113230/1 "2024-04-19T10:38:42Z")

</div>

My goal is to click the cell in heatmap and got its index.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/b/3b1f33b1465fc824a066684dd433f49e0c5a3c68.png)  
Currently it is implemented the following way

```julia
on(events(f).mousebutton, priority = 2) do event
        if event.button == Mouse.left && event.action == Mouse.press
            i = 0
            _, i = pick(ax.scene)
            i = i - size(m, 1) - 2
        end
    end

```

And indexing is done by pick() and it is implemented weirdly:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f961183b57c34878a4813d9630ea8fe1fa76596.png)  
Do you know how to change it so it will take one color cell as an index, not half of one and half of another cells?

It seems it somehow related with tick position

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 19, 2024, 10:47am UTC](https://discourse.julialang.org/t/how-to-correctly-pick-the-index-of-heatmap-cell/113230/2 "2024-04-19T10:47:06Z")

</div>

The indices are related to the vertices of the primitives used to render, some kind of mesh I guess. Have a look at how `DataInspector` converts this information, maybe it helps [Makie.jl/src/interaction/inspector.jl at f51eb527806e184690b577e17e630e9c9c521cb9 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/blob/f51eb527806e184690b577e17e630e9c9c521cb9/src/interaction/inspector.jl#L623-L631)

---

<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 19, 2024, 11:28am UTC](https://discourse.julialang.org/t/how-to-correctly-pick-the-index-of-heatmap-cell/113230/3 "2024-04-19T11:28:16Z")

</div>

This worked!

```julia
  on(events(f).mousebutton, priority = 1) do event
        if event.button == Mouse.left && event.action == Mouse.press
            i = 0
            plot, i = pick(ax.scene)
            a = DataInspector(plot)
            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[] = b[1]
            var_i[] = b[2]
            println(chan_i[], ' ', var_i[])
        end
    end
    f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e8b1c1d9d6cca95d7c99b0a20c925aaa1772dcf.png)
