# How to interactively change attributes of plots in GLMakie?

**URL:** <https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876>\
**Category:** New to Julia\
**Tags:** plotting, glmakie\
**Created:** [September 25, 2024, 3:00pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876 "2024-09-25T15:00:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![heinfleuren](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@heinfleuren](https://discourse.julialang.org/u/heinfleuren)\
**Post date:** [September 25, 2024, 3:00pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/1 "2024-09-25T15:00:34Z")

</div>

I’m relatively new to Julia and I’m trying to design a logistics application with GLMakie. Depending on some interactions I want to change the colors and markers on a map. I used Observables but it doesn’t work… What am I doing wrong??

```julia
using GLMakie

fig = Figure(backgroundcolor = :lightgrey)
ax = Axis(fig[1, 1] )
limits!(ax, 0, 10, 0, 10)

loc_color = Observable(:black)
loc_mark = Observable(:circle)
p1 = scatter!(ax, 5, 8, color = loc_color, marker=loc_mark, markersize = 20)

b1 = false
but1 = Button(fig[1,2], tellheight = false)
on(but1.clicks) do n
    if (b1)
        loc_color[] = :red
        loc_mark[] = :circle
    else
        loc_color[] = :green
        loc_mark[] = :utriangle
    end
    b1 = !b1
 end

fig

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 25, 2024, 3:20pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/2 "2024-09-25T15:20:41Z")

</div>

> [@heinfleuren](#):
>
> `loc_color `

you need: `loc_color[] = new_value`, and you don’t need a notify…

---

<div class="post-metadata">

**Author:** ![heinfleuren](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@heinfleuren](https://discourse.julialang.org/u/heinfleuren)\
**Post date:** [September 25, 2024, 3:29pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/3 "2024-09-25T15:29:09Z")

</div>

Thanks, sdanisch,  
I was surprised that I didn’t do that but something went wrong in my copy. It was in my code. I removed the notify’s but still it is not working…  
I changed the code above as it is in my VScode.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 25, 2024, 3:34pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/4 "2024-09-25T15:34:27Z")

</div>

I get “global b1 not defined in local scope”.  
Try:

```julia
using GLMakie

fig = Figure(backgroundcolor = :lightgrey)
ax = Axis(fig[1, 1] )
limits!(ax, 0, 10, 0, 10)

loc_color = Observable(:black)
loc_mark = Observable(:circle)
p1 = scatter!(ax, 5, 8, color = loc_color, marker=loc_mark, markersize = 20)

global b1 = false
but1 = Makie.Button(fig[1,2], tellheight = false)
on(but1.clicks) do n
    global b1
    if (b1)
        loc_color[] = :red
        loc_mark[] = :circle
    else
        loc_color[] = :green
        loc_mark[] = :utriangle
    end
    b1 = !b1
end

```

---

<div class="post-metadata">

**Author:** ![heinfleuren](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@heinfleuren](https://discourse.julialang.org/u/heinfleuren)\
**Post date:** [September 25, 2024, 4:28pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/5 "2024-09-25T16:28:16Z")

</div>

Yet, it works now!  
But:… it don’t get it fully why I need the ‘global’ definitions: does that have to do with the scope of the on…end code block?  
Thanks!

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 25, 2024, 4:55pm UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/6 "2024-09-25T16:55:51Z")

</div>

I think the relevant docs for that are here:  
[docs](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#on-soft-scope)

---

<div class="post-metadata">

**Author:** ![heinfleuren](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@heinfleuren](https://discourse.julialang.org/u/heinfleuren)\
**Post date:** [September 26, 2024, 5:53am UTC](https://discourse.julialang.org/t/how-to-interactively-change-attributes-of-plots-in-glmakie/119876/7 "2024-09-26T05:53:20Z")

</div>

Thanks! Helpful
