# How to plot in for loop (or map)

**URL:** <https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 28, 2020, 12:21am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881 "2020-01-28T00:21:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 28, 2020, 12:21am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881/1 "2020-01-28T00:21:08Z")

</div>

would somebody help to plot plots in for loop?

here is a simple not working example:

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

```

---

<div class="post-metadata">

**Author:** ![kevinczimmerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinczimmerman/32/13040_2.png) [@kevinczimmerman](https://discourse.julialang.org/u/kevinczimmerman)\
**Post date:** [January 28, 2020, 12:28am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881/2 "2020-01-28T00:28:06Z")

</div>

Try putting plot!() after the end.

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 28, 2020, 12:33am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881/3 "2020-01-28T00:33:05Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 28, 2020, 12:35am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881/4 "2020-01-28T00:35:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 28, 2020, 12:38am UTC](https://discourse.julialang.org/t/how-to-plot-in-for-loop-or-map/33881/5 "2020-01-28T00:38:09Z")

</div>

Ah, yes indeed!
