# Obtaining the axis of a \`Colorbar\`

**URL:** <https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207>\
**Category:** Specific Domains\
**Tags:** makie, makielayout\
**Created:** [August 28, 2021, 6:14am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207 "2021-08-28T06:14:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 28, 2021, 6:14am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/1 "2021-08-28T06:14:59Z")

</div>

I am trying to implement a scroll-behaviour on a `Colorbar` placed in a gridlayout cell (e.g. `fig[1,2]`).  
However, I cannot find out, how to obtain the corresponding axis, which I need to `register_interaction!(ax)` the scroll events.  
So how does one obtain the axis of a given `GridPosition` or how does one get the axis from the `cb=Colorbar(fig[1,2])` call?  
I tried to call `ax = Axis(fig[1,2])` for the same cell after the `Colorbar` was created, and this sort of works, but gives odd behaviour, as this seems to be a new axis, slightly displayed from the actual colorbar, which is seen, if you limit its size.

---

<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:** [August 28, 2021, 7:09am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/2 "2021-08-28T07:09:28Z")

</div>

There’s no axis, only a scene, which doesn’t have the more complex interaction machinery, only base events. You get it via cbar.scene

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 28, 2021, 7:23am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/3 "2021-08-28T07:23:03Z")

</div>

Hmm. I see. So that means, I need to go via the “on()” mechanism to hook into mouse scroll events on the colorbar and test for mousepositon being inside the scene of the colorbar?

---

<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:** [August 28, 2021, 7:41am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/4 "2021-08-28T07:41:48Z")

</div>

I think so, yes

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 28, 2021, 10:44am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/5 "2021-08-28T10:44:20Z")

</div>

Unfortunately `cb.scene` does not work. Did you mean `cb.parent`?

---

<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:** [August 28, 2021, 10:52am UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/6 "2021-08-28T10:52:31Z")

</div>

Oh maybe I refactored it at some point and it doesn’t have its own scene. Then you just have to check if the mouse is in the colorbar rectangle, for the main figure scene

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 28, 2021, 12:26pm UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/7 "2021-08-28T12:26:12Z")

</div>

I see. Any hint on how to determine the corresponding rectangle either to the subfigure [1,2] or the colorbar?

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 28, 2021, 2:19pm UTC](https://discourse.julialang.org/t/obtaining-the-axis-of-a-colorbar/67207/8 "2021-08-28T14:19:11Z")

</div>

I think I figured it out:

```julia
    scene = cb.parent.scene
    on(events(scene).scroll, priority = 2) do event
        mouse = scene.events.mouseposition[]
        c_start = cb.layoutobservables.suggestedbbox.val.origin
        c_stop = cb.layoutobservables.suggestedbbox.val.origin .+ cb.layoutobservables.suggestedbbox.val.widths
        if ! (all(mouse.>c_start) && all(mouse .<c_stop))
            return Consume(false)
        end 
      ....
    end

```
