julia lang - Plots.jl: plots inside for cycle -


i using plots.jl gr backend.

for whatever, cannot seem able plot! inside for-loop:

using plots fn(m,x) = m*x plot([0, 10], [fn(1, 0), fn(1, 10)]) m in 2:4     plot!([0, 10], [fn(m, 0), fn(m, 10)]) end 

plot inside loop

oddly enough, same thing without using cycle works:

using plots fn(m,x) = m*x plot([0, 10], [fn(1, 0), fn(1, 10)]) plot!([0, 10], [fn(2, 0), fn(2, 10)]) plot!([0, 10], [fn(3, 0), fn(3, 10)]) plot!([0, 10], [fn(4, 0), fn(4, 10)]) 

plot without loop

that because plotting happens when plot object returned console, implicitly calls base.display function. display method on plot object generates plot see. objects generated within for cycle aren't automatically returned console, means can't see plot; can display them explicitly calling display:

using plots fn(m,x) = m*x plot([0, 10], [fn(1, 0), fn(1, 10)]) m in 2:4      display(plot!([0, 10], [fn(m, 0), fn(m, 10)])) end 

or

p = plot([0, 10], [fn(1, 0), fn(1, 10)]) m in 2:4      plot!(p, [0, 10], [fn(m, 0), fn(m, 10)]) end p 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -