Plot inside a function

Consider the function

using Plots
function test_plot()
    a = Any[]
    t = [1,2,3]
    push!(a, [2,3,4])
    push!(a, [3,4,5])
    plot(t, a[1])
    return a
end

data  = test_plot()

When it is executed, the plot does not show in the Juno IDE. However, if I type the plot command in the REPL, the plot shows:

plot(data[1])

How does one execute plotting commands from within a function so that the plot shows interactively in the Plots window in the Juno IDE? Thanks.

Call display() on the plot object (there are other ways, see: The plot (with Plots pkg) not displayed, if plot(...) is not the last operator)

1 Like

Thanks!