# Inserting a row or column in a Makie layout

**URL:** <https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910>\
**Category:** General Usage\
**Tags:** makie, makielayout\
**Created:** [March 15, 2022, 11:23am UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910 "2022-03-15T11:23:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 15, 2022, 11:23am UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/1 "2022-03-15T11:23:27Z")

</div>

Say I have an existing grid like this one:

```julia
using CairoMakie

f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
f

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/9/4958bae29a3d48be5b2a229f96fee55d7dd38374.png)

How can I insert a column between these two?

An idea would be to move everything contained in `f[1,2]` to `f[1,3]`), but can I do that?

---

<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:** [March 15, 2022, 2:55pm UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/2 "2022-03-15T14:55:53Z")

</div>

GridLayoutBase has `insertrows!`and cols, should be exported?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 15, 2022, 4:39pm UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/3 "2022-03-15T16:39:46Z")

</div>

Thanks! Yes it’s exported, though not by Makie itself so I used it like this:

```julia
f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
Makie.GridLayoutBase.insertcols!(f.layout, 2, 1)
Label(f[1,2], "Some text", tellheight=false)
f

```

![image](https://global.discourse-cdn.com/julialang/original/3X/b/a/baa543824f7502c3ab3e0869bb6206735b9178d5.png)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 15, 2022, 4:52pm UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/4 "2022-03-15T16:52:07Z")

</div>

I’m still curious though: is there a way to move a slot’s content to another slot?

---

<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:** [March 16, 2022, 6:20am UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/5 "2022-03-16T06:20:02Z")

</div>

You just assign it to a new location. If you don’t have the object you can use `content()` or if there are multiple objects `contents()` like `f[1,4] = content(f[1,1])`. The thing to remember is that the setindex operation on GridLayouts just connects an object to a layout, it doesn’t copy anything and it removes any previous connection there might have been, as each layoutable object can only have one parent.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 16, 2022, 7:17am UTC](https://discourse.julialang.org/t/inserting-a-row-or-column-in-a-makie-layout/77910/6 "2022-03-16T07:17:51Z")

</div>

Perfect, thanks!

For completeness here’s the code using that approach:

```julia
f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
f[1,3] = content(f[1,2])
Label(f[1,2], "Some text", tellheight=false)
f

```
