"Redistribute" makie subplots

Say that I have created a Makie figure filling

fig = Figure()
ax1 = Axis(fig[1, 1]; ...)
ax2 = Axis(fig[1, 2]; ...)
ax3 = Axis(fig[1, 3; ...)
ax4 = Axis(fig[1, 4]; ...)

Where I here have a 1x4 set of plots. Is there a way to redistribute this to a 2x2 plot? Even better, is there a Makie function that let’s me “automatically” make a square-ish set of plots from my plots?

I have a case where I add n subplots to a Makie plot. I can loop through idx = 1:n, and add them to a vector. But it would be nice with a way to then compress things a little…

You can reposition by doing fig[1,3] = ax. You can call trim!(fig.layout) to remove excess rows.

For squarish you can do cols = ceil(Int, sqrt(n)) and then for (i, j) in fldmod1(idx, cols)

1 Like