# Plots and display

**URL:** <https://discourse.julialang.org/t/plots-and-display/105060>\
**Category:** Visualization\
**Tags:** plots, makie, animations\
**Created:** [October 17, 2023, 11:38am UTC](https://discourse.julialang.org/t/plots-and-display/105060 "2023-10-17T11:38:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 17, 2023, 11:38am UTC](https://discourse.julialang.org/t/plots-and-display/105060/1 "2023-10-17T11:38:58Z")

</div>

I am doing a cheap animation by displaying a plot every 1/60th of a second using the Plots package. Unfortunately, it is not very fast. It happens that this is the call to the display function that is slow.

This can be seen already at the repl.

```
  julia> @time Plots.plot(rand(2), rand(2))
    0.000373 seconds (402 allocations: 42.781 KiB)

  julia> @time display(Plots.plot(rand(2), rand(2)))
    0.002729 seconds (4.85 k allocations: 383.812 KiB)

```

Is there a faster way to update the plot in the window from a script?

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [October 17, 2023, 12:05pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/2 "2023-10-17T12:05:12Z")

</div>

Are you open to using a different plotting package? GLMakie has some good options here, where you can update an `Observable` and the plot just updates without redrawing.

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [October 17, 2023, 12:17pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/3 "2023-10-17T12:17:05Z")

</div>

GLMakie.jl is fast, other alternatives: GR.jl, Gnuplot.jl and Gaston.jl

Maybe you can test also the GR backend in Plots.jl, but using GR.jl directly is faster then through Plots

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 17, 2023, 1:16pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/4 "2023-10-17T13:16:48Z")

</div>

Yes, I can try to use GR directly. What would be the GR equivalent to the Plots call

```
    Plots.plot([0,1], [1,0], xlims=(-1.2,1.2), ylims=(-1.2,1.2), title = "",
               legend = false, grid = false, showaxis = false, 
               linecolor = :black, size = (600,600))

```

?  
I have browsed GR.jl documentation (and source) but I was unable to find the list of parameters available to the plot command. At the moment, I just need to draw a line between two points (no grid, no box, no axis, just a line).

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 17, 2023, 8:13pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/5 "2023-10-17T20:13:19Z")

</div>

I tried with GR.jl, but it is not faster than Plots with the GR backend. I guess I will try Makie.

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [October 18, 2023, 11:25am UTC](https://discourse.julialang.org/t/plots-and-display/105060/6 "2023-10-18T11:25:49Z")

</div>

```julia
0.002729 seconds

```

from your @time output. That is \> 358 Hz. Isn’t that enough for your use case (plot at 60 Hz)?

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 18, 2023, 1:33pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/7 "2023-10-18T13:33:00Z")

</div>

I am plotting more than two points!

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [October 18, 2023, 2:29pm UTC](https://discourse.julialang.org/t/plots-and-display/105060/8 "2023-10-18T14:29:52Z")

</div>

If you’d like to try Makie, the equivalent would be

```julia
using GLMakie

lines([0, 1], [1, 0], color=:black,
      axis=(limits=(-1.2, 1.2, -1.2, 1.2),
            xgridvisible=false, ygridvisible=false),
      figure=(resolution=(600, 600),))

```

For the animation you can do something like this:

```julia
using GLMakie

# You can prepare the figure and axis config like this,
# and pass them to `update_theme!` or to a plot function as done below
figure = (resolution=(600, 600),)
axis = (limits=(-1.2, 1.2, -1.2, 1.2),
        xgridvisible=false, ygridvisible=false)

points = Observable([Point2f(0,1), Point2f(1,0)])
lines(points, color=:black; figure, axis)

# The previous line opens a window and shows the initial plot
# You can then update it using `point[]` to change the array of points

for i = 1:100
    points[] = push!(points[], rand(Point2f))
    sleep(1/60)
end

```
