using Reactive, Interact
using PyPlot

f = figure();

α=slider(1:0.1:3)
β=slider(1:0.1:3)
γ=slider(1:0.1:3)
replot = button("Replot") # Commit your changes
map(display, [α, β, γ, replot]) # optional

coeffs = sampleon(replot, lift(tuple, α, β, γ))

@manipulate for x = coeffs; withfig(f) do
        plot(fun(x...))
    end
end

Sorry, in my rush to reply, I left behind some typos and bad thinking.
Tried this, it works.

On Tue, Sep 9, 2014 at 2:28 PM, Andrei Berceanu <andreiberce...@gmail.com>
wrote:

> Thank you both for the suggestions! I am currently trying the "Replot"
> button approach, but ran into some errors, as follows:
>
> using Reactive, Interact
> using PyPlot
>
> fun(α, β, γ) = cos(α + sin(β+γ)) #example function
>
> f = figure();
>
> α=slider(1:0.1:3)
> β=slider(1:0.1:3)
> γ=slider(1:0.1:3)
> replot = button("Replot") # Commit your changes
> map(display, α, β, γ, replot) # optional
> -->  `start` has no method matching start(::Slider{Float64})
>
> sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
> -->  redo not defined
>
> withfig(f)
> @lift plot(apply(fun, sampled_coeffs))
> --> `withfig` has no method matching withfig(::Figure)
>
>
> On Monday, September 8, 2014 6:10:59 PM UTC+2, Shashi Gowda wrote:
>>
>> John's suggestion is also a good way to do this. You can sample the
>> signals at a specific interval instead of on button clicks:
>>
>> # At 2 fps, with repeats dropped.
>> sampled_coeffs = droprepeats(sampleon(fps(2), lift(tuple, α, β, γ)))
>>
>> On Mon, Sep 8, 2014 at 9:36 PM, Shashi Gowda <shashi...@gmail.com> wrote:
>>
>>> Unfortunately, the @manipulate macro can only rerun the expression at
>>> every update of any of its input.
>>>
>>> What you need here is Reactive
>>> <http://julialang.org/Reactive.jl/api.html#sample-and-merge>'s
>>> `sampleon` function:
>>>
>>> using Reactive, Interact
>>> f = figure();
>>>
>>> α=slider(1:0.1:3)
>>> β=slider(1:0.1:3)
>>> γ=slider(1:0.1:3)
>>> replot = button("Replot") # Commit your changes
>>> map(display, α, β, γ, replot) # optional
>>>
>>> sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
>>>
>>> withfig(f)
>>>
>>> @lift plot(apply(fun, sampled_coeffs))
>>>
>>> IPython doesn't do update on release, Interact, in fact, uses the same
>>> widgets. What it does do is have at most 4 updates at any given time in the
>>> processing pipeline (any more updates replace the last update in the queue).
>>>
>>> On Mon, Sep 8, 2014 at 8:45 PM, Andrei Berceanu <andreib...@gmail.com>
>>> wrote:
>>>
>>>> Another option would be to use drop-down boxes with selectable values
>>>> or custom text boxes instead of sliders, at least as a temporary fix.
>>>> Anyone knows how I can do that?
>>>> By the way, iirc, IPython does have the update-on-release mechanism
>>>> implemented in their interactive widget functionality.
>>>>
>>>> On Monday, September 8, 2014 4:10:05 PM UTC+2, John Myles White wrote:
>>>>>
>>>>> I suspect the only way to do this is to change Interact so that it
>>>>> exposes a minimum time threshold before it registers a state change.
>>>>>
>>>>>  — John
>>>>>
>>>>> On Sep 8, 2014, at 4:16 AM, Andrei Berceanu <andreib...@gmail.com>
>>>>> wrote:
>>>>>
>>>>> > I have some code along the lines of
>>>>> >
>>>>> > f = figure()
>>>>> > @manipulate for α=1:0.1:3, β=1:0.1:3, γ=1:0.1:3; withfig(f) do
>>>>> >         y = fun(α,β,γ)
>>>>> >         PyPlot.plot(x, y)
>>>>> >     end
>>>>> > end
>>>>> >
>>>>> > where fun is a *very slow* function to evaluate. Is there any way to
>>>>> tell @manipulate to update the resulting plot only after I release the
>>>>> sliders? Otherwise what I get is, I release them to the desised values and
>>>>> then have to wait ages for all the intermediate plots to be drawn.
>>>>> >
>>>>> > Tnx!
>>>>>
>>>>>
>>>
>>

Reply via email to