Makie col/rowsize for grid, unexpected(?) behaviour

Greetings everyone,

Suppose we have the following figure in GLMakie:

using GLMakie

f = Figure()

Axis(f[1, 1])
Axis(f[2, 1])
Axis(f[2, 2])

colsize!(f.layout, 1, Fixed(300))
rowsize!(f.layout, 2, Fixed(300))
rowsize!(f.layout,1,Aspect(1,0.2))
colsize!(f.layout,2,Aspect(1,1))
f

Here, everything works perfectly fine.

However, if I try to do the same “col/rowsize treatment” on axes that are part of a grid layout, as follows, I get an error saying “row 2 is invalid”.

f = Figure()
m = f[1,1]
n = f[1,2]

Axis(m[1, 1])
Axis(m[2, 1])
Axis(m[2, 2])

Axis(n[1,1])

colsize!(m.layout, 1, Fixed(300))
rowsize!(m.layout, 2, Fixed(300))
rowsize!(m.layout,1,Aspect(1,0.2))
colsize!(m.layout,2,Aspect(1,1))

What would be the correct way to do this?

Also, I was wondering whether I could avoid using fixed col and row sizes and achieve the same behaviour with relative sizes (bottom left plot should be square). Any suggestions would be appreciated!

m is not a GridLayout, you’d need to instantiate that on its own to mutate it:

f = Figure()
m = GridLayout(f[1,1])
n = f[1,2]

Axis(m[1, 1])
Axis(m[2, 1])
Axis(m[2, 2])

Axis(n[1,1])

colsize!(m, 1, Fixed(300))
rowsize!(m, 2, Fixed(300))
rowsize!(m,1,Aspect(1,0.2))
colsize!(m,2,Aspect(1,1))
f

To your other question, you can use Aspect referencing a Relative for example, although Aspect is not great in interactively resized windows when you either make width much larger than height, or the other way around.

f = Figure()

Axis(f[1, 1])
Axis(f[2, 1])
Axis(f[2, 2])

colsize!(f.layout, 1, Relative(0.6))
rowsize!(f.layout,2,Aspect(1, 1))
f
1 Like

Excellent, thanks a lot for clarifying!
Also, would there be a way in this case to save only one part of the layout?
Something like Makie.save("plot.png", m)
(which doesn’t work here).

Not really, because content can in principle overlap into neighboring areas, even though that usually looks bad. You could write some code that checks the boundaries of some subgridlayout you’re interested in and crops the full image or svg to that area.

1 Like

Understood, thanks for the reply!
I reckon in this case it might be better to create an extra figure with the desired content only, and save that instead.