# Error/plotting inside a loop

**URL:** <https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019>\
**Category:** New to Julia\
**Tags:** plots\
**Created:** [June 30, 2023, 1:42pm UTC](https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019 "2023-06-30T13:42:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trandul](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@Trandul](https://discourse.julialang.org/u/Trandul)\
**Post date:** [June 30, 2023, 1:42pm UTC](https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019/1 "2023-06-30T13:42:05Z")

</div>

Greetings everyone, so I have the following simple code with a for loop in which I want to calculate the distance a car has travelled every 10 minutes. I would like to plot each “spot” it is calculated in the for loop and add it in the diagram. But for some reason I get the error “Cannot convert Float64 to series data for plotting” in the 12th line! What could I do to overcome this problem?

```julia
using Plots
function f()
    v = 119 #km/hour
    D = 0.0 #distance
    t_tot = 2.0 #total hours
    dt = 1/6 #10 minute interval
    nt = t_tot/dt; #number of iterations
    t = 0.0
    for i in 1:nt
        t = t .+dt
        D = D .+v*dt 
        p = scatter!(t,D)
    display(p)
    sleep(0.3)
    end
end
f()

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [June 30, 2023, 1:47pm UTC](https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019/2 "2023-06-30T13:47:18Z")

</div>

You probably need to do `scatter!([t], [D])`

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 30, 2023, 1:54pm UTC](https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019/3 "2023-06-30T13:54:06Z")

</div>

And to save 2 brackets: `scatter!((t,D))`

---

<div class="post-metadata">

**Author:** ![Trandul](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@Trandul](https://discourse.julialang.org/u/Trandul)\
**Post date:** [June 30, 2023, 2:15pm UTC](https://discourse.julialang.org/t/error-plotting-inside-a-loop/101019/4 "2023-06-30T14:15:32Z")

</div>

Ah yes it worked!! The solution was much simpler than I expected ahahha. Thank you so much!
