JuliaGizmos / InteractBase.jl

Build interactive HTML5 widgets in Julia
Other
27 stars 23 forks source link

slider rate and plotting - slider experience #63

Closed AshtonSBradley closed 6 years ago

AshtonSBradley commented 6 years ago

I find the slider really useful for exploring data graphically. However, at present when using @manipulate for plots, the slider sometimes feels a bit laggy: If you click somewhere on the slider, then that particular index value is quickly evaluated, giving a rapid display. But if you actually try to slide the slider, the only practical option is to slide rather slowly. A rapid slide at any point will lead to a freeze, followed by display of the plot for the final index value.

Here is an example using PyPlot:

using PyPlot, InteractBase
t = linspace(0,1,100) |>collect
x = linspace(-10,10,100) |>collect
f1 = figure(figsize=(10,2))
@manipulate for j in eachindex(t)
    withfig(f1,clear=true) do
        plot(x,sin.(t[j]*x))
    end
end

where the difference should be seen between moving the slider slowly, dragging rapidly to the end, and clicking to the end. Perhaps this is something to do with PyPlot or my laptop graphics, but at present the slider can feel quite clunky even for modest slide rates. I am curious as to whether others have this experience, especially if it persists on better hardware.

Would it be possible to change the behavior so that if the slide rate is faster than "slow" (whatever is continuously frame rendered), then the slider just serves up the final value, much like clicking on the slider would do. This would feel a lot more responsive to work with.

piever commented 6 years ago

It may also depend on the plotting backend. For example:

import GR
using InteractBase
t = linspace(0,1,100)
x = linspace(-10,10,100)
@manipulate for j in eachindex(t)
    GR.plot(x, sin.(t[j]*x))
end

updates instantaneously on my machine (but the machine has good specs and GR is a very efficient backend). I haven't been able to set up PyPlot here, so I can't really test it.

If the computation is too intense (for example let's say I have 10000 points in my plot), one trick is to throttle, which means only update at a fixed time interval. Not sure what would be a good timestep, but you could try:

@manipulate throttle = 0.05 for j in eachindex(t) # update at most once every 0.05 secs
    withfig(f1,clear=true) do
        plot(x,sin.(t[j]*x))
    end
end