Makie: New Figure w/ multiple LScenes auto-resizing when undesired

Hi, I’m trying to learn the new Figure system to combine animated LScenes with contour plots. I generate a curve for the camera eyepos and lookat and values for the plots for each frame. I’ve figured out all of that but now I have this recurring issue where if the surface plots contained in the LScenes change too much in a frame, some other internal threshold in the renderer gets triggered and something about the scene gets resized or otherwise qualitatively changed and it’s really jarring. I’ve attached a rendered .gif example with the two LScenes where they occasionally spaz out gif (~60MB, thank you if you look at it!) . This didn’t happen when I only had one scene, I could create a render that was very smooth.I’ve been trying to mess with a lot of the internal attributes of the various plots and trying to change them from auto to various fixed values, since it seems like it’s triggering some layouting issue and that’s what causes the spaz. But I’m having trouble pinpointing exactly where it might be. Here’s some of the relevant pieces of the code as well (sorry if it’s a little large, I’m not sure which pieces are relevant so I’ll post most of the figure generation/manipulation code):

fig = MakieLayout.Figure(resolution=(1280,1280), title="Iteration 0")
lscene = LScene(fig[2,1], scenekw = (camera = cam3d!, raw=false); height=650, width=450, tellwidth=false, tellheight=false, alignmode=Outside())
surfscene = GLMakie.surface!(lscene, ts, xs, zs[1])
surfaxis = lscene.scene.plots[1]
surfaxis.attributes.names.axisnames[] = ("t", "x", "u")
surfaxis.input_args[1][] = GeometryBasics.HyperRectangle{3,Float32}(Float32[-0.05, -0.05, -1.1], Float32[1.1, 2.1, 2.2])
surfobs = lscene.scene.plots[2].input_args[3]
colsize!(fig.layout, 1, Fixed(500)
lscenediff = LScene(fig[2,2], scenekw = (camera = cam3d!, raw=false); height=650, width=450, tellwidth=false, tellheight=false, alignmode=Outside())
# this continues like above for this lscene
colsize!(fig.layout, 2, Fixed(500))
rowsize!(fig.layout, 2, Fixed(700)
hm_bottom_sublayout = GridLayout()
fig[3,1:2] = hm_bottom_sublayout
hm_bottom_sublayout.height = 300
colorbar = hm_bottom_sublayout[1, 1] = Colorbar(fig, surfscene; width=10)
axiscontour = hm_bottom_sublayout[1, 2] = Axis(fig, title="u vs t-x")
contourscene = GLMakie.contourf!(axiscontour, ts, xs, zs[1])
contourplot = axiscontour.scene.plots[1]
contourobs = contourplot.input_args[3]
#this continues like above for the second contourf/colorbar
title = fig[1,:] = Label(fig, "Learning Iteration: 0")
rowsize!(fig.layout, 3, Fixed(200))
rowsize!(fig.layout, 1, Fixed(50))
focal_point = [0.5f0, 1.0f0, 0.0f0]
record(fig, video_filename; framerate=24, compression=20) do io
    for i in 1:length(parameter_vectors)
            cam_position = Float32.(focal_point .+ 1.2 .* [3 * cos(i/30), 4 * sin(i/30), 2.0 + 3.0 * sin(i/50)])
            AbstractPlotting.update_cam!(lscene.scene, cam_position, focal_point)
            AbstractPlotting.update_cam!(lscenediff.scene, cam_position, focal_point)
            imod = ((i - 1) % length(parameter_vectors)) + 1
            surfobs.val[:] .= @view zs[imod][:]
            contourobs.val[:] .= @view zs[imod][:]
            surfobsdiff.val[:] .= @view diffs[imod][:]
            contourdiffobs.val[:] .= @view diffs[imod][:]
            title.elements[:text].text[] = "Learning Iteration: $(i * 10)"

That looks weird but I don’t think it’s a layouting issue. LScenes don’t have protrusions so their content doesn’t affect the layout at all. Looks more like something jumpy in the projection, are you sure there can’t be anything wrong in that part? I wonder why two scenes could cause such an issue. Could you maybe post stills from when it goes haywire? I couldn’t stop the gif and maybe the way it looks could give a clue to what’s up

I figured it out, in my scene update loop I needed to update the cameras after I updated the plot data instead of cameras before plot data. It must have sometimes been resetting the camera position due to large plot data changes.

Here’s the fixed gif (~64MB, sorry!) if you’re interested, thanks again for helping, that clue was useful in tracking down the issue! :slight_smile:

I think the auto-recentering behavior of scenes can be disabled, something with center false, don’t quite remember

Ah I understand now, what triggers the recentering is the small layout jiggle that comes from the axis labels of the colorbars etc changing. That changes the pixel area of the LScenes’ scenes and that causes recentering by default. You can use tight_ticklabel_spacing! to disable auto tick space resizing if that jitter annoys you in your animation. Or just set a value manually in ax.yticklabelspace etc

I wanted the colors to stay the same range throughout anyways so I messed with the color ranges and levels for the contours and that fixed the jiggle issue as well. Here’s a final one (mp4 this time, only ~2MB) if you’d like to see. It’s not the same run as the previous examples: I’m generating many of these to summarize different runs. Thanks again for all the help!

1 Like

Pretty! I’m currently working on a 3d axis that reacts to the rotating camera and has better labels, that could also help in the future