# Makie: Removing gridlayouts

**URL:** <https://discourse.julialang.org/t/makie-removing-gridlayouts/103935>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [September 16, 2023, 6:42pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935 "2023-09-16T18:42:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Post date:** [September 16, 2023, 6:42pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/1 "2023-09-16T18:42:42Z")

</div>

I’m wondering if I can remove a GridLayout from a figure. Elements can be easily removed with `delete!` but this does not work on an entire GridLayout. If I want the layout of a figure programatically by deleting items that were in a gridlayout, I’m currently left with white space.

---

<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:** [September 17, 2023, 6:10am UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/2 "2023-09-17T06:10:52Z")

</div>

You can `trim!` a layout to remove empty columns and rows. And there’s `GridLayoutBase.remove_from_layout!` or something like that to remove a GridLayout from a parent layout

---

<div class="post-metadata">

**Author:** ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Post date:** [September 17, 2023, 2:09pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/3 "2023-09-17T14:09:42Z")

</div>

Okay I’m still confused. I guess you meant `GridLayoutBase.remove\_from\_layout!, but I cannot call this on a GridLayout. Secondly, I don’t understand how trim! works. I have a Gridlayout in another GridLayout.

```julia
gl.parent
GridLayout[1:4, 1:3] with 7 children
 ┣━ [1:2, 1:3] Box
 ┣━ [1, 2] Button
 ┣━ [2, 2] Button
 ┣━ [1, 1] GridLayout[1:2, 1:1] with 2 children
 ┃ ┣━ [1, 1] Label
 ┃ ┗━ [2, 1] Label
 ┃
 ┣━ [1:2, 3] GridLayout[1:2, 1:1] with 2 children
 ┃ ┣━ [1, 1] Axis
 ┃ ┗━ [2, 1] Button
 ┃
 ┣━ [3, 2] GridLayout[1:1, 1:3] with 3 children
 ┃ ┣━ [1, 2] Label
 ┃ ┣━ [1, 1] Button
 ┃ ┗━ [1, 3] Button
 ┃
 ┗━ [4, 2] GridLayout[1:1, 1:1] with 0 children

```

I added the gridlayout at `[4,2]` as a test, and since it has 0 children, I would think It should get trimmed off. However, calling `trim!(gl.parent), doesn’t actually do anything?

---

<div class="post-metadata">

**Author:** ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Post date:** [September 17, 2023, 2:45pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/4 "2023-09-17T14:45:52Z")

</div>

Okay, in this case I found `deleterow(gl.parent, 4)` works. Wouldn’t it make sense for `delete!` to also offer a method for gridlayouts? I tend to think of them as them as higher order elements, so to me it’d make sense to be able to delete them the same way I can delete a button or some other element.

---

<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:** [September 17, 2023, 3:12pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/5 "2023-09-17T15:12:31Z")

</div>

`trim!` removes all completely empty rows and columns, you have to remove the nested gridlayouts first or they’ll count as elements. It might actually make sense to add `delete!` for `GridLayout` as well, it’s a completely different type than the `Block`s that it normally applies to, but you’re right that they sometimes appear in similar contexts.

---

<div class="post-metadata">

**Author:** ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Post date:** [September 17, 2023, 3:47pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/6 "2023-09-17T15:47:12Z")

</div>

Thanks for the answer. So how do I delete them otherwise at the moment for trim! to work? Removing them by hand with `deleteat!` from the contents (or something like that) didn’t work as expected.

---

<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:** [September 17, 2023, 3:51pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/7 "2023-09-17T15:51:56Z")

</div>

Ah the signature was `remove_from_gridlayout!(gc::GridContent)` so the `GridContent` of a `GridLayout` is in `gridlayout.layoutobservables.gridcontent[]`, admittedly not user-friendly 🙂 Would you mind opening an issue about adding `delete!` in GridLayoutBase.jl?

---

<div class="post-metadata">

**Author:** ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Post date:** [September 17, 2023, 3:52pm UTC](https://discourse.julialang.org/t/makie-removing-gridlayouts/103935/8 "2023-09-17T15:52:37Z")

</div>

I’ll open one now!
