Makie 3D "flatten" scatter points in x-y axis

Hi there,

I’m trying to make a 3D plot with Makie, and I’d like to plot some scatter points “flat” on the x-y plane of the plot.

Here is the M(not)WE I have so far:

using CairoMakie

# Initialize figure
fig = Figure(size = (800, 400))

# Initialize Axis
ax = Axis3(fig[1, 1])

# Make scatter plot points (on the "floor")
scatter!(ax, [0, 0.5], [0, -0.5], [-0.5, -0.5], markersize = 0.2, markerspace = :data, marker = Circle, strokewidth = 2)

# Make Contour plots
contour3d!(ax, 
	-1:0.1:1, 
	-1:0.1:1, 
	(x, y) -> -x^4+x^2 + y^2,
	levels = 10,
	linewidth = 4,
	transparency = true
)

fig

Which gives me this:

I would like to see the two blue scatter points as if they were plotted on the 2D XY plane. Is there a way to do this?
I read the documentation and tried finding something similar online, but couldn’t. Maybe I’m not familiar with the terminology to ask a proper question :sweat_smile:.

If that makes sense, I’d like them to turn into tilted ellipses to give them proper perspective in the plot (as if they were 2D images drawn on the floor of the 3D box).

Thanks in advance!

scatter is not really made for these kinds of marker transformations I think, at least I tried markerspace = :data and that didn’t look correct in 3d (maybe that’s just an implementation omission in CairoMakie though).

You could use poly! and that will transform the coordinates accordingly:

f = Figure()
ax = Axis3(f[1, 1])

contour3d!(ax, 
	-1:0.1:1, 
	-1:0.1:1, 
	(x, y) -> -x^4+x^2 + y^2,
	levels = 10,
	linewidth = 4,
	transparency = true
)

poly!(ax, Circle(Point2f(-0.5, -0.5), 0.2))
f

2 Likes

That’s perfect! Thanks!

scatter is not really made for these kinds of marker transformations I think, at least I tried markerspace = :data and that didn’t look correct in 3d (maybe that’s just an implementation omission in CairoMakie though).

Billboarding (that markers face the camera) isn’t controlled by markerspace. You need to set rotation for that. Here you can use Vec3f(0,0,1) to turn billboarding off and have marker facing upwards. This should work in all backends nowadays. (CairoMakie doesn’t apply perspective projection to markers but iirc Axis3 has very little of that by default)

Edit: Turning off billboarding requires both markerspace = :data and rotation