Plot inside a function?

function f()
    Plots.plot(1:20)
end

function g()
    Plots.plot(1:20)
    return 1.0
end

in the above, calling f() would produce a plot, however, calling g() does NOT. Why? and how to fix it? thanks.

Here is why

function f()
    p = Plots.plot(1:20)
    return p
end

function g()
    Plots.plot(1:20)
    return 1.0
end

Function f() return the content of a plot while function g() returns a float64

So does it mean that I have to return a Plot for a function to plot???

I mean, I want the function plots something (in the middle of a function) but return something else. Is it possible?

I see, the solution is to use display() like:

function g()
    display(Plots.plot(1:20) )
    return 1.0
end
1 Like