6

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

rashid
  • 644
  • 7
  • 18
noahkiwi
  • 63
  • 3

2 Answers2

3

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
BatWannaBe
  • 4,330
  • 1
  • 14
  • 23
0

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)

Bill
  • 5,600
  • 15
  • 27
  • Hi, thanks for your answer. I tested your solution, but the problem is (as you already mentioned), that the white circles draw over other things in my plot. I suppose that there has to be a different solution to this problem like the function delete in Matlab. – noahkiwi Nov 14 '21 at 13:38