# Clearing a scene in Makie

**URL:** <https://discourse.julialang.org/t/clearing-a-scene-in-makie/43790>\
**Category:** Visualization\
**Created:** [July 27, 2020, 8:35pm UTC](https://discourse.julialang.org/t/clearing-a-scene-in-makie/43790 "2020-07-27T20:35:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [July 27, 2020, 8:35pm UTC](https://discourse.julialang.org/t/clearing-a-scene-in-makie/43790/1 "2020-07-27T20:35:41Z")

</div>

I have a visualization with sub-scenes. `scene2` displays a polyline with text labels. Polylines change depending on mouse selections in `scene1`. I would like to be able to clear `scene2` in example below at commented line:

```julia
using Makie, Random, Formatting

scene = Scene(resolution = (1200, 1500))

scene1 = Scene(scene, IRect(0, 0, 1200, 900))
image = rand(1:4, 640, 480)
image!(scene1, image, scale_plot = false, show_axis = false, interpolate = false, colormap=[:white, :blue, :green, :red])

scene2 = Scene(scene, IRect(0, 900, 1200, 600))
poly = Vec2f.(1:10, rand(10))
lines!(scene2, poly)

for p in poly
  text!(scene2, format("({:.3f}, {:.3f})", p[1], p[2]), position = p, textsize = 0.1, color = :red)
end

display(scene)

on(scene1.events.mousebuttons) do buttons
  if ispressed(scene1, Mouse.left)
    global scene2
    
    poly = Vec2f.(1:10, rand(10))
    # clear scene2 here
    lines!(scene2, poly)
    
    for p in poly
      text!(scene2, format("({:.3f}, {:.3f})", p[1], p[2]), position = p, textsize = 0.1, color = :red)
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [July 28, 2020, 3:54am UTC](https://discourse.julialang.org/t/clearing-a-scene-in-makie/43790/2 "2020-07-28T03:54:28Z")

</div>

Here is a hack, which works (callback part only listed below):

```julia
on(scene1.events.mousebuttons) do buttons
  if ispressed(scene1, Mouse.left)
    global scene2
    
    while length(scene2) > 1
      delete!(scene2, scene2[end])
    end

    poly = Vec2f.(1:10, rand(10))
    lines!(scene2, poly)
    
    for p in poly
      text!(scene2, format("({:.3f}, {:.3f})", p[1], p[2]), position = p, textsize = 0.1, color = :red)
    end

    println(length(scene2.plots))
  end
end

```

but I suspect, there is a more elegant way of doing it.
