Statically rotate 3D scene in Makie.jl

I am plotting a bivariate normal distribution in Makie. After generating the values, I plot it with this code (full MWE below):

fig = Figure()
ax1 = Axis3(fig[1,1], xlabel="Selection error term", ylabel="Outcome error term")
s = surface!(ax1, XY, XY, grid)

where XY is a vector with x and y values defining a regular grid the same shape as grid. I get this nice-looking scene:

I want to rotate the scene so that I am looking at it with negative X to the left and ahead, and positive Y to the right and ahead, so 90 degrees to the right of where the camera is now. I can do this in the GLMakie window by dragging, and it looks like I want it to, but I need to be able to do it programatically. I’ve tried a number of different ways (listed below), but I can’t get the camera to a position where the Z axis doesn’t look too flat (somehow I seem to be clobbering the Z exaggeration when I move the camera), and the axis ticks are on the side of the figure towards the camera.

Full MWE:

using GLMakie, Distributions
const XY = collect(range(-3, 3, length=100))
const ρ = 0.7
dist = MvNormal([0, 0], [1 ρ; ρ 1])

grid = zeros(Float64, (100, 100))

for (x, i) in enumerate(XY)
    for (y, j) in enumerate(XY)
        grid[x, y] = pdf(dist, [i, j])
    end
end
  
fig = Figure()
ax1 = Axis3(fig[1,1], xlabel="Selection error term", ylabel="Outcome error term")
surface!(ax1, XY, XY, grid)

Things I’ve tried (all at the end after the surface! call):

Seems to only rotate the camera to point in the wrong direction, also flattens the scene. I’ve tried putting the 90 in each position, and also tried with \pi in case it’s expecting radians.

cam3d!(ax1.scene)
rotate_cam!(ax1.scene, 0, 90, 0)

Not sure what this does. I thought it would move the camera to (5, -5, 1) looking at (0, 0, 0) but I can’t figure out what it actually did:

    cam3d!(ax1.scene)
    update_cam!(ax1.scene, [0, 0, 0], [5, -5, 1])
1 Like

Images of the last two examples:

Axis3 has the attributes azimuth and elevation, which control the angles you’re interested in. Increase azimuth by pi/2 I guess?

That works, thanks!

1 Like