# Creating a rasterized 3D surface plots inside vectorized figure

**URL:** https://discourse.julialang.org/t/creating-a-rasterized-3d-surface-plots-inside-vectorized-figure/86569
**Category:** General Usage
**Tags:** plotting, makie, glmakie
**Created:** [August 30, 2022, 7:29pm UTC](https://discourse.julialang.org/t/creating-a-rasterized-3d-surface-plots-inside-vectorized-figure/86569 "2022-08-30T19:29:12Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 30, 2022, 8:54pm UTC](https://discourse.julialang.org/t/creating-a-rasterized-3d-surface-plots-inside-vectorized-figure/86569/2 "2022-08-30T20:54:41Z")

</div>

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 😉

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

```julia
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)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e04fa51b8009239328eb2e31cecafce0c5c363c.jpeg)

---

_[View the full topic](https://discourse.julialang.org/t/creating-a-rasterized-3d-surface-plots-inside-vectorized-figure/86569)._
