'tight_layout' in Makie for plots with multiple subplots

In your case:

image

Code
# create data
x = range(-1, 1, 129)
y = range(-1, 1, 129)

X = ones(length(y)) .* x'
Y = y .* ones(1,length(x))
R = sqrt.(X.^2 + Y.^2)

Z = ((R.^2 .- 1.5) .^ 2)
Z[R.>1] .= 0

clim = (0, maximum(Z)*4)

# create figure
fig_w = 2*(3+3/8)   # in inch
fig_h = 2.5           # in inch
size_pt = 72 .* (fig_w, fig_h)

set_theme!(lightposition=Vec3f(0, 2, 1))

cmap1 = Reverse(:Spectral_4)

fig = Figure(resolution=size_pt)

hm2 = []

for i in 1:4

    ax1 = Axis3(fig[1,i]; elevation=pi/8, azimuth=-pi/6, protrusions=0)

    surface!(ax1, X, Y, i*Z, shininess=200f0, specular=Vec3f(0.8), colormap=cmap1,
        colorrange=clim, rasterize=10)
    
    limits!(ax1, -1, 1, -1, 1, clim...)

    hidedecorations!(ax1)
    hidespines!(ax1)

    ax2 = Axis(fig[2,i])

    hm = heatmap!(ax2, X, Y, i*Z, colormap=cmap1, colorrange=clim)
    push!(hm2, hm)

    hidedecorations!(ax2)
    hidespines!(ax2)

	colsize!(fig.layout, i, Aspect(1, 1.0))
end


cb = Colorbar(fig[1:2,5], hm2[end])

save("test_fig.pdf", fig, pt_per_unit=1)

fig

and the PDF looks fine and sharp.

1 Like