Plotting within a call function (MWE)

I am experimenting with callbacks, in particular, interactive plotting from within a callback. Here is my code, which runs, except that I do not see a plot displayed. I must be doing something wrong! I am working with Visual Studio Code. Project.toml only contains Plots.jl . I am using Julia 1.8.5 . Thanks for any insights!

import Plots

function fct(alpha, x)
    return tanh(alpha .* x)
end

function cb(alpha, i, step, x)
    if i % step == 0
        y = fct.(alpha, x)
        println(y)
        Plots.plot(x, y, label = "alpha = $alpha")
    end
end

x = 0 : .1 : 10
cbb(alpha, i, step) = cb(alpha, i, step, x)
    
function demo(cb::Function)
    for i in 1:1000
        alpha = i  / 800.
        cb(alpha, i, 50)
    end
end

demo(cbb)
cb(.5, 20, 10, x)

Try Plots.plot(x, y, label = "alpha = $alpha") |> display

Perfect! I keep forgetting to apply display! Thanks for the reminder.

1 Like