# Using push! on a plot with time objects

**URL:** https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750
**Category:** General Usage
**Created:** [May 4, 2020, 5:06pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750 "2020-05-04T17:06:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![achugb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achugb/32/8080_2.png) [@achugb](https://discourse.julialang.org/u/achugb)
#### Post date: [May 4, 2020, 5:06pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750/1 "2020-05-04T17:06:42Z")

</div>

Is there a way to push additional datapoints to a plot when using time objects? The code below throws an error. Am I doing something wrong?

```julia
using Plots
using Dates

x = [now(), now() + Second(1)]
p = plot(Time.(x), 1:2)
push!(p, Time(now()), 2)
MethodError: no method matching push!(::Plots.Plot{Plots.GRBackend}, ::Time)

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 4, 2020, 5:15pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750/2 "2020-05-04T17:15:59Z")

</div>

You probably want `plot!(p, Time(now()), 2)`

---

<div class="post-metadata">

### Author: ![achugb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achugb/32/8080_2.png) [@achugb](https://discourse.julialang.org/u/achugb)
#### Post date: [May 4, 2020, 5:26pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750/3 "2020-05-04T17:26:29Z")

</div>

That seems to add new plot series when I try it?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 4, 2020, 5:32pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750/4 "2020-05-04T17:32:35Z")

</div>

Yes `plot!` will add a new series to an existing figure, as Plots redraws the figure if you want to change things - there’s no real updating of existing Plots. You might want to look at Makie.jl if you really need this, alternatively you can do

`plot!(p, Time(now()), 2, color = 1, label = "")`

to redraw the figure with your additional points in another series with the same color and no additional label.

---

<div class="post-metadata">

### Author: ![achugb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achugb/32/8080_2.png) [@achugb](https://discourse.julialang.org/u/achugb)
#### Post date: [May 4, 2020, 6:17pm UTC](https://discourse.julialang.org/t/using-push-on-a-plot-with-time-objects/38750/5 "2020-05-04T18:17:10Z")

</div>

Makie looks super interesting. Thanks!  
I was hoping to use the push! function kind of like this guy does  
[https://stackoverflow.com/questions/57827245/julia-plotting-push-adds-to-wrong-line](https://stackoverflow.com/questions/57827245/julia-plotting-push-adds-to-wrong-line)
