Equally sized grid cells in Makie

Hi,

I am trying to place 5 plots in a grid with 3 rows and 4 columns so that

  • the first plot spans cols 2:3 in row 1
  • the remaining plots span cols 1:2, 3:4 in rows 2,3
  • all plots are of the same size

However, it seems that Makie is taking the labelling of the xticks and yticks into account when calculating the size of the plot cells (in the MWE plots c and e are smaller than b,d).


Is there a way to fix this, i.e. make all plots the same size?

Thank you in advance for your help.

using Makie, CairoMakie, MakieTeX
ns = [1,2,3,4,5,6]

nams = ["a","b","c","d","e"]
titles = nams
j = 1
f = Figure(resolution=(794, 1123))
axes = [Axis(f[1,2:3]),
Axis(f[2, 1:2]),
Axis(f[2,3:4]),
Axis(f[3, 1:2]),
Axis(f[3,3:4])]


Label(f[end+1, :], text = L"\mathrm{Error}")
Label(f[2:end-1, 0], text = L"$n$",
    rotation = pi/2)


for nam in nams 
    axe = axes[j] 
    if j == 1
        axe.xlabel=L"\mathrm{Error}"
        axe.ylabel=L"$n$"
    end 
    if j ∈ [3,5]
        axe.yticklabelsvisible = false
        axe.yticksvisible = false
    end 
    axe.title = titles[j] 
    axe.yticks = ((1:6), string.(ns))
    axe.limits = ([-5,5],[0,6])
    j +=1
end 
f

The reason this doesn’t produce equally wide axes, is that the left protrusions of axis 1 become part of the first column gap, and this is added to the width of the left-column axes because they span across that gap. One way you can get around that is to pretend that axis 1 doesn’t have protrusions on the left, by using alignmode = Mixed(left = Makie.Protrusion(0)). This will work without problem in your specific layout, because there isn’t anything to the left of axis 1 which could collide.

ns = [1,2,3,4,5,6]

nams = ["a","b","c","d","e"]
titles = nams
j = 1
f = Figure(resolution=(794, 1123))
axes = [Axis(f[1,2:3]),
Axis(f[2, 1:2]),
Axis(f[2,3:4]),
Axis(f[3, 1:2]),
Axis(f[3,3:4])]

axes[1].alignmode = Mixed(left = Makie.Protrusion(0))

Label(f[end+1, :], text = L"\mathrm{Error}")
Label(f[2:end-1, 0], text = L"$n$",
    rotation = pi/2)


for nam in nams 
    axe = axes[j] 
    if j == 1
        axe.xlabel=L"\mathrm{Error}"
        axe.ylabel=L"$n$"
    end 
    if j ∈ [3,5]
        axe.yticklabelsvisible = false
        axe.yticksvisible = false
    end 
    axe.title = titles[j] 
    axe.yticks = ((1:6), string.(ns))
    axe.limits = ([-5,5],[0,6])
    j +=1
end 
f

Amazing, thanks for the help