How to plot in for loop (or map)

would somebody help to plot plots in for loop?

here is a simple not working example:

x=0:0.1:1
plot(x,x)
for i=2:3
    plot!(x,i.*x)
end

Try putting plot!() after the end.

1 Like

calling plot() in local scope does not cause printing plot automatically. Try this:

x=0:0.1:1
p=plot(x,x)
for i=2:3
    plot!(p, x,i.*x)
end

# display(p)
p # p alone is ok

Just p is enough at the end - you just need to evaluate the plot object.

Ah, yes indeed!

1 Like