Best way to let axis automatically adjust in live GLMakie plot?

I’m plotting some numbers produced by my simulation using GLMakie. The code looks somewhat like this:

data = Observable([[0.0], [0.0]])
series(data)

while sim_is_running
    # do stuff
    push!(data[][1], result1)
    push!(data[][2], result2)

    notify(data)
end

This seems to work fine, however, the axis limits do not adjust when new points are added to the plot. I could add a listener to data that manually calls autolimits!, but that seems a bit wasteful (not least because it will add a second redraw unless I am missing something). Is there a better way to do this?

You can call reset_limits! (similar to autolimits! but doesn’t revert ax.limits if it’s set) and that doesn’t redraw (drawing is separate). But it gets slower and slower the larger your data set is, because each time it has to iterate over all points of all plots. If you only care about this dataset you can just keep track of the limits yourself, update them for each new incoming piece of data, and set limits!(ax, ...) directly instead. This will just update the projection and ticks without iterating over all of the data.

1 Like