# What is a good way to delete lines in Makie?

**URL:** <https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [May 3, 2021, 6:19pm UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478 "2021-05-03T18:19:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 3, 2021, 6:19pm UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478/1 "2021-05-03T18:19:35Z")

</div>

I have a diagram in a layout that is changing depending on user input. This means I need to delete the line and change the axis label again and again. What is the best way to do that?

This is my current approach, but it causes problems when used in a layout:

```julia
using GLMakie

const objects = []

function plot_sin(fig)
    if length(objects) > 0
        delete!(objects[end])
    end
    ax=Axis(fig[1, 1], xlabel = "time [s]", ylabel = "sin")
    x = 0:0.1:10*pi
    y = sin.(x)
    po = lines!(x,y)   
    push!(objects, ax) 
end

function plot_cos(fig)
    if length(objects) > 0
        delete!(objects[end])
    end
    ax=Axis(fig[1, 1], xlabel = "time [s]", ylabel = "cos")
    x = 0:0.1:10*pi
    y = cos.(x)
    po = lines!(x,y)   
    push!(objects, ax) 
end

function main(gl_wait=true)
    fig=Figure()

    @async begin
        for i in 0:2
            plot_sin(fig)
            sleep(2)
            plot_cos(fig)
            sleep(2)
        end
    end

    gl_screen = display(fig)
    if gl_wait
        wait(gl_screen)
    end
    return nothing
end

main()

```

Any better way?

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [May 3, 2021, 8:58pm UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478/2 "2021-05-03T20:58:33Z")

</div>

If you can get by with adjusting input positions or attributes do that. (I.e. make a node `points = Node(Point2f0.(x, y))`, pass it to lines and adjust that and the attributes you need.)

Otherwise you can `delete!` plots from the scene they’re on, i.e.

```julia
fig = Figure()
ax = Axis(fig[1, 1])
s = scatter!(ax, rand(10))
delete!(ax.scene, s)
fig

```

That should also be a lot faster than deleting and recreating axes.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 4, 2021, 1:11pm UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478/3 "2021-05-04T13:11:08Z")

</div>

Thank you, using a node of points works:

```julia
using GLMakie

const p1 = Node(Vector{Point2f0}(undef, 6000)) # 5 min
const y_label = Node("")

function plot_sin(x)
    y_label[]="sin"
    y = sin.(x)
    p1[] = Point2f0.(x, y)
end

function plot_cos(x)
    y_label[]="cos"
    y = cos.(x)
    p1[] = Point2f0.(x, y)
end

function main(gl_wait=true)
    fig=Figure()
    ax=Axis(fig[1, 1], xlabel = "time [s]", ylabel = y_label)
    x_1 = 0f0:0.1f0:10f0*pi
    x_2 = 0:0.1:5*pi
    plot_sin(x_1)
    po = lines!(p1)   

    @async begin
        for i in 0:2
            plot_sin(x_1)
            sleep(2)
            plot_cos(x_2)
            sleep(2)
        end
    end

    gl_screen = display(fig)
    if gl_wait
        wait(gl_screen)
    end
    return nothing
end

main()

```

But the x axis is not re-scaled when the number of points changes.

How can I achieve that?

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [May 4, 2021, 1:19pm UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-delete-lines-in-makie/60478/4 "2021-05-04T13:19:38Z")

</div>

Call `autolimits!(ax)` or `xlims!(ax, min, max)` after updating your input.
