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

Viewed 317

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

2 Answers

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

What I've used in the past to erase part of a scatter plot is to redraw the dots using the background color (white is the default I believe). If you have several layers on the plot, you may need to redraw the ones you want to keep, though, since the overwriting may erase other features if present underneath:

julia> scene = scatter([0],[0], color="blue", markersize=10)

julia> scene = scatter([0],[0], color="white", markersize=10)

Related