# \`rowsize!\` and \`colsize!\` for nested layouts

**URL:** <https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981>\
**Category:** Specific Domains\
**Tags:** makielayout\
**Created:** [August 25, 2021, 2:32pm UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981 "2021-08-25T14:32:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 25, 2021, 2:32pm UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981/1 "2021-08-25T14:32:13Z")

</div>

I am writing code which generates a specific layout with interactions etc. It works fine for a figure, but as soon as I try to embed it as a subfigure I am getting into trouble. The reason is that `rowsize!` and `colsize!` fail when called for a layout rather than a whole figure. Here is an example:

```julia
fig = Figure()
subfigure = fig[1,1]
plot(subfigure[1,1],cos.(1:0.1:10), color=:green)
plot(subfigure[2,1],sin.(1:0.1:10), color=:red)
rowsize!(subfigure.layout,2,Auto(2)) # fails
plot(fig[2,1],sqrt.(1:0.1:10), color=:red)
rowsize!(subfigure.layout,2,Auto(2)) # does not what it is supposed to do, i.e. changing the relative size of the rows in the subfigure

```

Any idea how to achieve the relative row or column size specification such that is also works for type `GridPosition`, i.e. a sub-layout?

---

<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:** [August 25, 2021, 6:05pm UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981/2 "2021-08-25T18:05:14Z")

</div>

subfigure is only a GridPosition, the description of a position in a GridLayout but not a GridLayout itself. Do `subfigure = fig[1, 1] = GridLayout()` to make the layout explicit instead of implicit. Then you can do `rowsize!(subfigure,...` directly.

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 26, 2021, 6:49am UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981/3 "2021-08-26T06:49:35Z")

</div>

Thanks for the quick reply. So now this code works:

```julia
using GLMakie
fig = Figure()
subfigure = fig[1,1] = GridLayout()
plot(subfigure[1,1],cos.(1:0.1:10), color=:green)
plot(subfigure[2,1],sin.(1:0.1:10), color=:red)
rowsize!(subfigure,2,Auto(2)) # works
plot(fig[2,1],sqrt.(1:0.1:10), color=:red)

```

but I am still stuck with the problem of writing a function which can receive a region in a figure (i.e. a subfigure) as an input and can put its layout inside this region.  
I tried `subfigure.layout = GridLayout()` but this is not allowed. Is there another way to assign the gridlayout to a subfigure region? Only then can I make a function that behaves like “image” or “plot”.  
How can this code example be corrected so that it does what it is supposed to do?

```julia
using GLMakie
function show!(fig_or_sub, rel_heigth)    
    fig_or_sub = GridLayout() # how to do this correctly?
    image(fig_or_sub[1,1], rand(10,10))
    plot(fig_or_sub[2,1],sin.(1:0.1:10), color=:red)
    rowsize!(fig_or_sub,2,Auto(rel_heigth)) 
end
fig = Figure() # example for two sub-figures
show!(fig[1,1], 1)
show!(fig[1,2], 2)

fig = Figure()
show!(fig, 2) # this should also work

```

Any help is appreciated.

---

<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:** [August 26, 2021, 8:28pm UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981/4 "2021-08-26T20:28:49Z")

</div>

If fig\_or\_sub is a Figure, you could place the `GridLayout` at position [1, 1], otherwise you place it at `fig_or_sub[]` which just means at that position.

```julia
function show!(fig_or_sub, rel_heigth)    
    gl = if fig_or_sub isa Figure
        fig_or_sub[1, 1] = GridLayout()
    else
        fig_or_sub[] = GridLayout()
    end
    image(gl[1,1], rand(10,10))
    plot(gl[2,1],sin.(1:0.1:10), color=:red)
    rowsize!(gl,2,Auto(rel_heigth)) 
end

##

fig = Figure()
show!(fig[1,1], 1)
show!(fig[1,2], 2)
fig

##

fig = Figure()
show!(fig, 2)
fig

```

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [August 27, 2021, 6:33am UTC](https://discourse.julialang.org/t/rowsize-and-colsize-for-nested-layouts/66981/5 "2021-08-27T06:33:39Z")

</div>

You are a star! Great. The assignment via the empty brackets `fig_or_sub[] = GridLayout()` solves the problem!
