# Multiple plots in Plots.jl

**URL:** <https://discourse.julialang.org/t/multiple-plots-in-plots-jl/31497>\
**Category:** Visualization\
**Created:** [November 25, 2019, 2:33pm UTC](https://discourse.julialang.org/t/multiple-plots-in-plots-jl/31497 "2019-11-25T14:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [November 25, 2019, 2:33pm UTC](https://discourse.julialang.org/t/multiple-plots-in-plots-jl/31497/1 "2019-11-25T14:33:42Z")

</div>

Why doesn’t the following work:

```julia
using Plots
pyplot()
p=plot(layout=2)
for i = 1:2
    plot!(p,rand(10),subplot=i)
end

```

while the following does work:

```julia
using Plots
pyplot()
p=plot(layout=2)
plot!(p,rand(10),subplot=1)
plot!(p,rand(10),subplot=2)

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 25, 2019, 2:45pm UTC](https://discourse.julialang.org/t/multiple-plots-in-plots-jl/31497/2 "2019-11-25T14:45:06Z")

</div>

Because `for` loops in julia do not return the value. A plot is produced when a `Plot` object is returned to the console (which implicitly calls `display` in Julia). So just typing `p` after your first code should work.

---

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [November 25, 2019, 4:20pm UTC](https://discourse.julialang.org/t/multiple-plots-in-plots-jl/31497/3 "2019-11-25T16:20:09Z")

</div>

Thanks!
