Creating a rasterized 3D surface plots inside vectorized figure

Yes this can be done with Makie, even with CairoMakie if your 3D scene is not too complex and can be drawn with simple z-sorting and layering.

I’ve tried to make an example sort of similar to what you showed here, but it’s not quite perfect yet. I would have liked to move the light source, and that’s supposed to be possible, but I’m not sure how to do it. Maybe @sdanisch or @ffreyer know. Just setting lightposition = Vec3f(.. on the surface call didn’t do anything.

Also the shading was wrong until I switched X and Y, and this must be because the normals were facing inwards first. Again I’m not sure how to control that better than trying out until it works :wink:

Here’s the example and a screenshot of the resulting pdf:

using CairoMakie

f = Figure()

r = range(0, 1.25, 100)
p = range(0, 2*pi, 100)
R = r' .* ones(length(r))
P = ones(length(p))' .* p
Z = ((R.^2 .- 1.5) .^ 2)

X = R .* cos.(P)
Y = R .* sin.(P)

ax3 = Axis3(f[1, 1], azimuth = 4.005530633326986 - pi)
surface!(ax3, Y, X, Z,
    shininess = 100f0,
    specular = Vec3f(0.8), colormap = :lightrainbow,
    rasterize = 3
)

scatter(f[1, 2], randn(100, 2))
lines(f[2, 1:2], cumsum(randn(100)))

save("test.pdf", f)

2 Likes