I’m new to Makie (used to use Plots before). I’ve been trying to align the ylabels for many subplots using the CairoMakie package. I’m able to align them, but for some reason there is some overlap with the tick marks of the plot… Here is my minimal working example:
f = Figure()
ax1 = Axis(f[1, 1], title = "Axis 1", ylabel = "y label", ytickformat = "{:.3f}")
ax2 = Axis(f[2, 1], title = "Axis 2", ylabel = "y label", xlabel = "x label")
ax3 = Axis(f[2, 2], title = "Axis 3", xlabel = "x label", xtickformat = "{:.3f}", xticklabelrotation = pi/4)
# Here is my addition to the code in the Makie tutorial
lines!(ax1, rand(length(times))*1e5)
lines!(ax2, rand(length(times))*1e2)
yspace = maximum(tight_yticklabel_spacing!, [ax1, ax2])
xspace = maximum(tight_xticklabel_spacing!, [ax2, ax3])
ax1.yticklabelspace = yspace
ax2.yticklabelspace = yspace
ax2.xticklabelspace = xspace
ax3.xticklabelspace = xspace
f
Ah that’s tricky The reason is that these days, the limits of an Axis don’t immediately update when a plot is added. That’s a performance optimization.
So when you measure the tick spacing, it’s not for the limits you see in the final plot, it’s for the initial limits. That’s why they’re too small.
To adjust the limits early, call reset_limits!(ax) on each axis.