# Makie workflow to access and change attributes of objects

**URL:** <https://discourse.julialang.org/t/makie-workflow-to-access-and-change-attributes-of-objects/89058>\
**Category:** Visualization\
**Tags:** plotting, makie\
**Created:** [October 21, 2022, 12:15pm UTC](https://discourse.julialang.org/t/makie-workflow-to-access-and-change-attributes-of-objects/89058 "2022-10-21T12:15:20Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [October 21, 2022, 8:05pm UTC](https://discourse.julialang.org/t/makie-workflow-to-access-and-change-attributes-of-objects/89058/5 "2022-10-21T20:05:55Z")

</div>

> [@weltenbummler](#):
>
> **Question 5** Removing the first legend via `delete!(leg1)` works in the sense that the legend is not displayed in the figure.

Disclaimer: This relies on `Makie, GridLayoutBase` internals and does not work for any plot elements (like `lines, scatter, ...`). Tested on `Makie v0.18.0`. (I am sorry @jules, but I could not resist 🙂 )

```julia
using Makie
using GLMakie
GLMakie.activate!()

function delete!(f::Figure, blk::Makie.Block)
    # remove from scene
    idx = findfirst(s -> s === blk.blockscene, f.scene.children)
    isnothing(idx) && error("could not find block in figure's scenes")
    deleteat!(f.scene.children, idx)
    layout = blk.layoutobservables.gridcontent[]
    # remove from layout
    l_idx = findfirst(l -> l === layout, f.layout.content)
    isnothing(l_idx) && error("could not find block in figure's layout")
    prev_parent = layout.parent
    Makie.GridLayoutBase.remove_from_gridlayout!(f.layout.content[l_idx])
    layout.parent = prev_parent
    Makie.GridLayoutBase.trim!(f.layout)
    return f # trigger a redraw to remove the blockscene's drawings
end

f = Figure()
ax = Axis(f[1,1])
lines!(ax, 1:3, 1:3, label="line1")
leg = Legend(f[1,2], ax)

display(f) # layout =^= [ax, leg]
delete!(f, leg) # layout =^= [ax]

```

EDIT: ~~I think the above does not work properly if you try to remove a block that is not located at the boundary of a layout. E.g. if you have a layout like (only 1 row) `[ax1, ax2, ax3]` and you call `delete!(f, ax2)` then the gap between `ax1` and `ax3` will not be removed…~~ Nevermind, it seems to work.

---

_[View the full topic](https://discourse.julialang.org/t/makie-workflow-to-access-and-change-attributes-of-objects/89058)._
