# Multiple plots created in loop

**URL:** <https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588>\
**Category:** Pluto\
**Tags:** plotting, pluto\
**Created:** [July 31, 2021, 8:48am UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588 "2021-07-31T08:48:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrOstir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krostir/32/27919_2.png) [@KrOstir](https://discourse.julialang.org/u/KrOstir)\
**Post date:** [July 31, 2021, 8:48am UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/1 "2021-07-31T08:48:08Z")

</div>

I would like to create multiple plots in a loop within Pluto. The question is related to [Plot inside a loop again[, but now in Pluto]](https://discourse.julialang.org/t/plot-inside-a-loop-again-but-now-in-pluto/49295).

This works as expected in Jupyter, but not in Pluto.

```julia
using Plots

for i in 1:3
    display(plot(rand(10)))
end

```

Is it possible to do the same in Pluto? Is this related to the [Multiple outputs and inputs per cell](https://github.com/fonsp/Pluto.jl/issues/7)?

Keep in mind that I am new to Pluto (and Julia) and the answer might be obvious.

---

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [July 31, 2021, 4:55pm UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/2 "2021-07-31T16:55:41Z")

</div>

Do you want to have separate plots or multiple lines in the same plot?

---

<div class="post-metadata">

**Author:** ![KrOstir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krostir/32/27919_2.png) [@KrOstir](https://discourse.julialang.org/u/KrOstir)\
**Post date:** [July 31, 2021, 5:06pm UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/3 "2021-07-31T17:06:06Z")

</div>

Sorry, I was not clear enough. I want separate plots.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [July 31, 2021, 6:36pm UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/4 "2021-07-31T18:36:21Z")

</div>

The easiest way is to make an array of plots!

```julia
plots = [plot(rand(100)) for i=1:3]

```

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [August 1, 2021, 7:50am UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/5 "2021-08-01T07:50:58Z")

</div>

> [@KrOstir](#):
>
> Is this related to the [Multiple outputs and inputs per cell](https://github.com/fonsp/Pluto.jl/issues/7)?

Yes.

You can do it in Ploto by

```julia
plot((plot(rand(100)) for i=1:3)...;
	size = default(:size) .* (1, 3), layout = (3, 1), left_margin = 5Plots.mm)

```

or

```julia
let
	n = 3
	PP = []
	for i in 1:n
		P = plot(rand(100))
		push!(PP, P)
	end
	plot(PP...; size = default(:size) .* (1, n), layout = (n, 1), left_margin = 5Plots.mm)
end

```

---

<div class="post-metadata">

**Author:** ![KrOstir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krostir/32/27919_2.png) [@KrOstir](https://discourse.julialang.org/u/KrOstir)\
**Post date:** [August 1, 2021, 8:15am UTC](https://discourse.julialang.org/t/multiple-plots-created-in-loop/65588/6 "2021-08-01T08:15:21Z")

</div>

This is exactly what I was looking for. Thanks, @genkuroki.
