plotjuliamakie.jl

How do I delete dots created by scatter! in Julia (using Makie)


I am quite new to Julia. I am currently working on a small program, which requires me to plot a dot and remove it later (there will only be one dot at every time). I am using the the Makie package to visualize everything, but I haven't found a way to delete a dot, which has been drawn by scatter (or scatter!). The code should look something like this:

scene = scatter([0],[0], color="blue", markersize=10)
pop!(scene.scatter) #command that removes the dot drawn by the above scatter

I found this thread (Julia Plotting: delete and modify existing lines) which shows one way to delete the last drawn thing using pop!, but this code doesn't run (I get an errormessage if I add scene as an argument of scatter!(scene,...)).

Thanks for any help


Solution

  • There is a delete!(ax::Axis, plot::AbstractPlot) method, but it's kind of messy so an example might be clearer:

    scene = scatter([0],[0], color="blue", markersize=10)
    # FigureAxisPlot instance
    # scene.plot is the Scatter instance
    
    points2 = scatter!(2:4, 2:4, color="green", markersize=20)
    # Scatter instance
    
    point3 = scatter!([1], [1], color="red", markersize=15)
    # Scatter instance
    
    delete!(scene.axis, points2)
    # green points removed from plot
    
    delete!(scene.axis, scene.plot)
    # original blue point removed from axis,
    # but scene.plot doesn't change