How to add labels to grid of tricontourf! in GLMakie

I am trying to add row and column labels to a grid of plots below. I am trying to adapt the solution here for my use case, but the plots are too small relative to the entire figure.

using GLMakie

x = randn(50)
y = randn(50)
z = x .* y

fig = Figure(backgroundcolor = :white)

for i ∈ 1:3
    Label(fig[i, 0], "row $i", color=:black, halign=:right, tellwidth=false)
    Label(fig[0, i], "column $i", color=:black, halign=:center, tellwidth=false)
end

for c ∈ 1:3, r ∈ 1:3
    ax = Axis(fig[r, c], aspect = DataAspect())
    tricontourf!(ax, x, y, z)
end
colgap!(fig.layout, 0)
rowgap!(fig.layout, 0)
display(fig)

When I remove the first loop for the labels, the subplots are the correct size. I am probably making a silly mistake, but I cannot figure out what it is.

The code was not executable (x was not defined).
To be sure to provide a working example, it is best to paste the code into a fresh julia session.


The “row $i” labels should have tellheight = false, rather than tellwidth.

1 Like

Sorry about that. x,y and z where in my global scope but did not make it into example. I corrected that above.

Ugh. It was a silly mistake. Using Label(fig[i, 0], "row $i", color=:black, halign=:right, tellheight=false) fixed the problem. Thanks for your help!

1 Like