It’s relatively unusual to want to set the padding between axis and figure border without taking the actual ticklabel sizes into account, as they could either clip outside or leave large whitespace. So you have to work around the fact that Makie wants to include those spaces.
Two variants come to mind, one is to place the axis outside the layout and just specify it’s bbox
argument as the figure size minus the padding (by default, the axis will align its inner area to the bbox
rectangle):
padding = 50
w, h = (600, 450)
f = Figure(size = (w, h), backgroundcolor = :gray)
Axis(f, bbox = BBox(padding, w-padding, padding, h-padding))
f
Another option is to use the layout mechanism and set the padding you want as the figure_padding
but at the same time overwriting all protrusions the Axis
reports with 0:
f = Figure(figure_padding = 50, backgroundcolor = :gray)
Axis(
f[1, 1],
alignmode = Mixed(
left = Makie.Protrusion(0),
right = Makie.Protrusion(0),
bottom = Makie.Protrusion(0),
top = Makie.Protrusion(0),
)
)
f
You can also do this with a parent layout if you want to add more elements to the figure but keep the overall padding. This way you don’t have to set alignmodes on all the individual elements:
f = Figure(figure_padding = 50, backgroundcolor = :gray)
gl = GridLayout(
f[1, 1],
alignmode = Mixed(
left = Makie.Protrusion(0),
right = Makie.Protrusion(0),
bottom = Makie.Protrusion(0),
top = Makie.Protrusion(0),
)
)
for i in 1:3, j in 1:2
Axis(gl[i, j])
end
Colorbar(gl[:, end+1])
f