# Real time plotting with Gadfly (Vehicle Trajectory Plotting)

**URL:** https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333
**Category:** Visualization
**Tags:** plotting, gadfly
**Created:** [December 1, 2021, 2:01am UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333 "2021-12-01T02:01:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)
#### Post date: [December 1, 2021, 2:01am UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/1 "2021-12-01T02:01:37Z")

</div>

Hello,

I would like to plot vehicle trajectory on a cartesian coordinate system in near-real time from the data that is coming from a datastream. Is it possible to do this in Gadfly.

My requirement is to push latest observation to the plot and make the plot update itself. I am looking for something similar what OnlineStats.jl does but I would like update the raw observations.

What would be the best plotting library for this purpose.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [December 1, 2021, 9:50am UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/2 "2021-12-01T09:50:20Z")

</div>

You can do it with GLMakie, for example:

```julia
using GLMakie
GLMakie.activate!()

f = Figure()

data = Observable([0f0, 1f0])

ax, lin = lines(f[1, 1], data)

running = Observable(false)

b = Button(f[2, 1],
    label = @lift($running ? "Stop stream" : "Start stream"),
    tellwidth = false
)

on(b.clicks) do c
    running[] =! running[]
    if running[]
        @async while running[]
            push!(data[], data[][end] + randn())
            notify(data)
            autolimits!(ax)
            sleep(1/60)
        end
    end
end

f

```

[https://i.imgur.com/U5RuEkt.mp4](https://i.imgur.com/U5RuEkt.mp4)

---

<div class="post-metadata">

### Author: ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)
#### Post date: [December 1, 2021, 1:17pm UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/3 "2021-12-01T13:17:19Z")

</div>

Thank you the response. I will definitely look into it.

One more question, Lets say, I let the code run indefinitely, push the data indefinitely, will I encounter a memory problem? How does makie handle these issues. Do you have any knowledge about it? Does it summarize or smoothe the old data to keep up?

Again thank you for the nice example.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [December 1, 2021, 9:13pm UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/4 "2021-12-01T21:13:08Z")

</div>

Yes of course, you can’t indefinitely push data into a vector. But you could just as well put some kind of online stats function in between, so that you limit the amount of data you show. That’s not really something that Makie is concerned with, it just shows the data.

---

<div class="post-metadata">

### Author: ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)
#### Post date: [December 1, 2021, 9:33pm UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/5 "2021-12-01T21:33:24Z")

</div>

Great idea. Thank you!

---

<div class="post-metadata">

### Author: ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)
#### Post date: [November 18, 2022, 8:27pm UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/6 "2022-11-18T20:27:41Z")

</div>

Is it possible to overlay plot to a map?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 18, 2022, 9:36pm UTC](https://discourse.julialang.org/t/real-time-plotting-with-gadfly-vehicle-trajectory-plotting/72333/7 "2022-11-18T21:36:11Z")

</div>

Yes, you can plot whatever you want under the lines
