Real time plotting (with Makie)

Hello,

I myself have been looking to acquire high frequency signals and display them with a good framerate. The MWE below runs with either static axes or “chart” style time scrolling. For simplicity I’m just filling up an array and using the system clock, but in practice data would come in chunks and plotting will be triggered by a hardware clock’s callback function (rather than the sleep timer)…

Anyhow: The bottom line is (in my hands) plotting via Observables is insanely quick, but if you want dynamic axes it really costs you. Granted there’s some overhead with timing but I am getting frame render times of ~0.1ms with static axes and 20ish ms with “updating”.

@sdanisch Is there a better way to handle this? I noticed the double updating I’ve used is also how you made the animation example in the Makie gallery. For most time signals you could get away with a static or “on event” scaling Y-axis and then a regularly changing X-axis. I’m guessing this could be much simpler and quicker than min maxing each frame???

MWE of faux streaming data w/Makie plots:

using Makie

scene = Scene()
data = Node(rand(1000))
t = lift(c -> length(c), data)
y = lift(a -> to_value(data)[max(1, a-999):max(a, 1000)], t)
#x = lift(b -> collect(max(b-999, 1):max(b, 1000)), t)
x = 1:1000 # for static axis
lines!(scene, x, y)

@time for i in 1:500
frametime = @elapsed begin
    push!(data, append!(to_value(data), rand(10)))
    #AbstractPlotting.update_limits!(scene) #comment out update calls for fixed axis
    #AbstractPlotting.update!(scene)
    end
    sleep(max(0.020-frametime, 0))
    println(frametime)
end
9 Likes