# Pluto and Plotting Inside a For Loop

**URL:** https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424
**Category:** General Usage
**Created:** [January 16, 2021, 4:04am UTC](https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424 "2021-01-16T04:04:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [January 16, 2021, 4:04am UTC](https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424/1 "2021-01-16T04:04:12Z")

</div>

Hello,

I’ve generated an array of composite types (which I’ve I’ve defined). Each composite type has two fields called `t` and `T` which contain equally sized vectors. Each composite type saved in my array represents a different case. I’d like to plot all the cases together so I try something like this (based on this [post](https://stackoverflow.com/questions/46141141/plots-jl-plots-inside-for-cycle) here)

```julia
begin
	p = plot( Array_of_Strucs[1].t, Array_of_Strucs[1].T, fmt=:png)
	for i ∈ 2:16
		plot!(p, Array_of_Strucs[i].t, Array_of_Strucs[i].T, fmt=:png)
	end
end

```

But nothing appears either in the terminal or in the notebook itself. No error either.

If I try to do them manually it will show up though, something like this:

```julia
begin
	plot( Array_of_Strucs[1].t, Array_of_Strucs[1].T, fmt=:png)
    plot!( Array_of_Strucs[2].t, Array_of_Strucs[2].T, fmt=:png)
    plot!( Array_of_Strucs[2].t, Array_of_Strucs[3].T, fmt=:png)
end

```

I am using `gr()` backend. I tried with `plotly()` and had the same issue.

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [January 16, 2021, 4:27am UTC](https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424/3 "2021-01-16T04:27:52Z")

</div>

Hm - I didn’t realize I had to define `i` I like that, wasn’t intuitive for me to do so. I tried it anyway and no change. Still nothing.

---

<div class="post-metadata">

### Author: ![Daniel\_Berge](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_Berge](https://discourse.julialang.org/u/Daniel_Berge)
#### Post date: [January 16, 2021, 4:28am UTC](https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424/4 "2021-01-16T04:28:53Z")

</div>

Your issue is that `for` loops return `nothing`. Your second example works because `plot!` returns a plot object. You’ll want to return the plot at the end.

```julia
begin
	p = plot( Array_of_Strucs[1].t, Array_of_Strucs[1].T, fmt=:png)
	for i ∈ 2:16
		plot!(p, Array_of_Strucs[i].t, Array_of_Strucs[i].T, fmt=:png)
	end
    p
end
```

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [January 16, 2021, 4:33am UTC](https://discourse.julialang.org/t/pluto-and-plotting-inside-a-for-loop/53424/5 "2021-01-16T04:33:05Z")

</div>

Good to remember that! Thank you! It works now 🙂
