2D plot flush with 3D axis?

I’m trying to plot a 2D graph underneath a 3D plot. The following is my hacky approach,

using GLMakie

fig = Figure()
menu = Menu(fig, options = [1,2])
fig[1, 1] = vgrid!(
    Label(fig, "Index a", width = nothing),menu;
    tellheight = false, width = 200)
ax = Axis3(fig[1, 2])

menu.selection[] = 1

function my_function(a,x)
    data = [sin.(pi*x), 5 .+ cos.(pi*x)]
    return data[a]
xplot = LinRange(-1,1,100)
yplot = cos.(pi*xplot)
zplot = @lift my_function($(menu.selection),xplot) 
plt = lines!(ax, xplot, yplot, zplot)

# I'd like this line to be flush against the bottom boundary
lines!(ax, -1:1, -1:1, Makie.@lift(ones(3)*minimum($zplot)))

on(menu.selection) do s


but the line isn’t flush with the bottom boundary.

Is there a way to plot a line flush against the bottom of an Axis3, and to have that update with autolimits!?

Yeah you just have to change the autolimit margins so there’s no additional space at the bottom. Without looking it up, I guess ax3.zautolimitmargin = (0, 0.05) could work.

Works like a charm. Thanks!

Shoot, I spoke to soon - it works for the first plot, but doesn’t refresh after menu selection.

If it doesn’t refresh, maybe your observable order is wrong and the axis updates first, then the data?

Sorry, my description may have been misleading.

The line plot starts out flush with the bottom upon running the script, but after a menu selection, the line is no longer flush with the bottom. I set ax.zautolimitmargin = (0.0,.05) and it stays the same after menu selection, but the plot no longer honors these limits.

Went with another approach for now - we switched to LScene() for zoom interactivity and turned off the axis (so there’s no need to flush the bottom plot with anything anymore).

I don’t know how to make autolimits! to work with LScene(), but with interactivity we can at least just move the plot around manually after menu.selection picks out a solution.