Whitespace in layout in Makie

I have a fairly involved layout, and I can’t see how to get the whitespace to be used up, while not forcing some figures to get pushed into others. If I make the resolution height smaller, I get overlap of rows, even though there is enough space in the final layout it doesn’t seem to resolve. If I make lots of height, I get extra whitespace. If I set rowgap manually, I end up in a tug of war. I want rows of decreasing heights, and to automatically have the plot resize to remove whitespace and have a tight bounding box. Is is possible?

The result with no overlap looks like

I suspect you already looked at the tutorial to fix spacing issues? Wouldn’t trim! do exactly what you want to do?

It would be helpful to know how you’ve set up your figure, as I can’t completely assess that from the image. It looks like you might have either given objects fixed heights, or use the aspect attribute on the lower axes, or something else non-standard. As long as you don’t set up impossible constraints, what you described should be easily possible.

I’ll just go with the sentence:

I want rows of decreasing heights, and to automatically have the plot resize to remove whitespace and have a tight bounding box

f = Figure()
[Axis(f[i, j]) for i in 1:3, j in 1:4]
rowsize!(f.layout, 1, Relative(0.5))
rowsize!(f.layout, 2, Relative(0.33))
f

And if you need the first axes square, and let’s say want the second row twice the height of the third row, this is how you’d do it, by giving the first row an Aspect of 1 to column 1 (all columns are the same anyway) and by giving row 2 size Auto(2) which means a ratio of 2 when handing out the remaining space (default for last row is 1):

f = Figure()
[Axis(f[i, j]) for i in 1:3, j in 1:4]
rowsize!(f.layout, 1, Aspect(1, 1))
rowsize!(f.layout, 2, Auto(2))
f

To understand how aspect ratios on axes can break the layout, and how it differs to set the aspect for a full row / column, look at the animation here Axis · Makie Plotting Ecosystem

5 Likes

thanks for this. I think my sublayout for the first row with aspect ratio 1 may not be playing so nicely with the other sizes. With this advice it looks like I can get what I need by avoiding sublayout

This link is broken. Is there an updated version?

https://makie.juliaplots.org/stable/tutorials/aspect-tutorial/