Hi,
I am trying to visualize a simulation live in makie.
However my plot is not updated in VSCode when the observable it depends on is changed. The following is my code:
function getStickPositions(c::Config)
unitVectorAlongStick=[cos(c.ϕ),sin(c.ϕ)];
leftPos=c.Rg-l/2*unitVectorAlongStick;
rightPos=c.Rg+l/2*unitVectorAlongStick;
return [[leftPos[1],rightPos[1]],[leftPos[2],rightPos[2]]]
end
currentConfig=Node(Config([0,1],0.1,[0,0],0));
fig=CairoMakie.Figure()
axis=Axis(fig[1, 1])
xlims!(axis,(-3,3))
ylims!(axis,(-1,3))
axis.aspect=DataAspect()
xPosObs=lift(c->getStickPositions(c)[1],currentConfig)
yPosObs=lift(c->getStickPositions(c)[2],currentConfig)
#drawConfig(fig,currentConfig)
Makie.lines!(axis,xPosObs,yPosObs)
display(fig)
fps = 20
nframes = 120
for i=1:nframes
currentConfig[]=updateConfig(currentConfig[],1/fps)
sleep(1/fps)
end
A “Config” is a state in the simulation which can be drawn. “updateConfig” implements the update logic for the simulation.
Once I type “fig” in the terminal, the correct figure is plotted again. However the existing is not updated when the observable it depends on changes.
What’s going wring here?
Cairomakie makes static pngs or svgs that are then shown in the vscode plot pane. Changing an observable updates the relevant axis / figure state but it neither causes a new representation of the figure to be shown, nor is the CairoMakie output in any way backlinked to the figure. The backends that can update displayed figures are GLMakie and WGLMakie. Glmakie uses native windows, wglmakie can be embedded in web contexts, so it should in principle also work in VSCode. But it’s the least polished of the three backends currently
Maybe google around for that one, I’m not a Linux user, sorry. It seems to me that I’ve seen similar things quite often, there’s some libc issue I think or sometimes graphics driver issues.