How to clear a plot from a scene with other elements in GLMakie

I think what you actually want is this. You do not need to delete your scatter, you can just update points with an empty array (you could also do empty!(points[]) and then notify(points)).

If you really want to delete the scatter completely for some reason, it’s better to do scat = scatter!(...) and then delete!(scene, scat).

using GLMakie
function gui()
    scene = Scene(camera=campixel!, size=(800, 600))
    points = Observable(Point2f[])
    scatter!(scene, points, color=:gray)
    btn = Button(scene, label="Clean")
    on(btn.clicks) do _
        points[] = []
    end
    on(events(scene).mousebutton) do event
        if event.button == Mouse.left
            if event.action == Mouse.press
                mp = events(scene).mouseposition[]
                push!(points[], mp)
                notify(points)
            end
        end
    end
    scene
end
gui()
1 Like