# GLMakie: Change attributes in existing Screen objects

**URL:** https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636
**Category:** Visualization
**Tags:** glmakie
**Created:** [February 14, 2023, 5:19pm UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636 "2023-02-14T17:19:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [February 14, 2023, 5:19pm UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/1 "2023-02-14T17:19:53Z")

</div>

I would like to change line attributes inside an already displayed GLMakie screen object.  
Below a simple example, unfortunately only the edge of the button changes.  
Are there any ideas. The purpose is:  
I would like to switch on and of line objects or change their color. Here my snippet:

```julia
using GLMakie
fig = Figure(resolution = (400, 400))
bt = Button(fig[1, 1]; label = "switch color", strokewidth = 4, tellheight = false, strokecolor = (:green))
ax = Axis(fig[2, 1]; title = "test", aspect=DataAspect(), tellheight = false)
l1 = lines!(ax, [1,2,3])
# ---
on(bt.clicks) do nclicks 
    if iseven(nclicks)
        bt.strokecolor = (:red)
        l1.attributes.attributes[:color] = (:red)
        ax.scene.plots[1].attributes.attributes[:color] = (:red)
    else
        bt.strokecolor = (:blue)
        l1.attributes.attributes[:color] = (:blue)
        ax.scene.plots[1].attributes.attributes[:color] = (:blue)
    end
end
# ---
resize_to_layout!(fig)
screen_obj = display(fig)
wait(screen_obj)

```

---

<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: [February 14, 2023, 5:30pm UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/2 "2023-02-14T17:30:47Z")

</div>

A simple `li.color = :red` should do it, the attributes and Axis stuff is unnecessary. What you’re doing I think is replacing the original color observables in the attribute dictionary by going into the internals like that.

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [February 14, 2023, 6:19pm UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/3 "2023-02-14T18:19:43Z")

</div>

Thanks for the suggestion!  
Modify: `ax.title = "new_text"` is possible in side `on() do [...] end`  
but `l1.color = :colorname` has no effect ☹  
I am lucky!  
`l1.visible = false`  
has an effect, in my case this is sufficient for the moment 🙂

```julia
using GLMakie
fig = Figure(resolution = (400, 400))
bt = Button(fig[1, 1]; label = "on/off", strokewidth = 4, tellheight = false, strokecolor = (:green))
ax = Axis(fig[2, 1]; title = "test", aspect=DataAspect(), tellheight = false)
l1 = lines!(ax, [1,2,3])
# ---
on(bt.clicks) do nclicks 
   if iseven(nclicks)
        l1.visible = true
        ax.title = "on"
        bt.label = "off"
    else
        l1.visible = false
        ax.title = "off"
        bt.label = "on"
    end
end
# ---
resize_to_layout!(fig)
scene_obj = display(fig)
wait(scene_obj)

```

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [February 14, 2023, 7:32pm UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/4 "2023-02-14T19:32:38Z")

</div>

This works: 🙂

```julia
[...]
on(bt.clicks) do nclicks 
    l1.visible = false
    if iseven(nclicks)
        l1.color = :red
    else
        l1.color = :blue
    end
    l1.visible = true
end
[...]

```

---

<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: [February 15, 2023, 10:07am UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/5 "2023-02-15T10:07:37Z")

</div>

Oh, can you open an issue here: [new issue](https://github.com/MakieOrg/Makie.jl/issues/new)?  
That sounds like a bug in the on demand renderloop not rendering a new frame, since there really should be no other reason why the color only updates after a visibility change…

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [February 15, 2023, 10:48am UTC](https://discourse.julialang.org/t/glmakie-change-attributes-in-existing-screen-objects/94636/6 "2023-02-15T10:48:35Z")

</div>

> [@sdanisch](#):
>
> Oh, can you open an issue here: [new issue](https://github.com/MakieOrg/Makie.jl/issues/new)?

It is really strange, I do not know why, today I tried to reproduce the error from yesterday,  
but failed. Therefore, under some circumstances, it might be that the change of line attributes  
fails and in this case switching visibility off/on might help.
