# Emptying figures in makie

**URL:** https://discourse.julialang.org/t/emptying-figures-in-makie/115425
**Category:** General Usage
**Created:** [June 10, 2024, 1:57pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425 "2024-06-10T13:57:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Davidbarber](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Davidbarber](https://discourse.julialang.org/u/Davidbarber)
#### Post date: [June 10, 2024, 1:57pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/1 "2024-06-10T13:57:44Z")

</div>

I have created a figure in GLMakie with an image and an IntervalSlider to adjust contrast. This works fine. If I empty the figure with empty!(fig) and then recreate the image plot object and the IntervalSlider plot object the latter does not work. Any insights as to why this is happening.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 10, 2024, 2:08pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/2 "2024-06-10T14:08:29Z")

</div>

Do you have a short example which code fails for you and what the error is?

---

<div class="post-metadata">

### Author: ![Davidbarber](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Davidbarber](https://discourse.julialang.org/u/Davidbarber)
#### Post date: [June 10, 2024, 6:49pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/3 "2024-06-10T18:49:48Z")

</div>

To keep things simple, look at the code example in the Makie documentation for IntervalSlider

using GLMakie #changed from CairoMakie

f = Figure()

#empty!(f)

Axis(f[1, 1], limits = (0, 1, 0, 1))

rs\_h = IntervalSlider(f[2, 1], range = LinRange(0, 1, 1000),

startvalues = (0.2, 0.8))

rs\_v = IntervalSlider(f[1, 2], range = LinRange(0, 1, 1000),

startvalues = (0.4, 0.9), horizontal = false)

labeltext1 = lift(rs\_h.interval) do int

string(round.(int, digits = 2))

end

Label(f[3, 1], labeltext1, tellwidth = false)

labeltext2 = lift(rs\_v.interval) do int

string(round.(int, digits = 2))

end

Label(f[1, 3], labeltext2,

tellheight = false, rotation = pi/2)

points = rand(Point2f, 300)

# color points differently if they are within the two intervals

colors = lift(rs\_h.interval, rs\_v.interval) do h\_int, v\_int

map(points) do p

(h\_int[1] \< p[1] \< h\_int[2]) && (v\_int[1] \< p[2] \< v\_int[2])

end

end

scatter!(points, color = colors, colormap = [:gray90, :dodgerblue], strokewidth = 0)

f

I have added , but commented out, #empty!(f)

If I run this script (using include in REPL) the results appear in a window. The Sliders work as they should. If I run the script a second time it also works ok.

If I now comment out the fig = Figure() line and uncomment the empty!(f) line

using GLMakie

#f = Figure()

empty!(f)

Axis(f[1, 1], limits = (0, 1, 0, 1))

.

# same code as above

.

f

the window appears as before but the Sliders don’t work. They look the same as before but cannot be activated.

I am relatively new to Makie and cannot see what I need to fix this.

Any ideas?

Thanks

---

<div class="post-metadata">

### Author: ![Davidbarber](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Davidbarber](https://discourse.julialang.org/u/Davidbarber)
#### Post date: [June 10, 2024, 6:50pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/4 "2024-06-10T18:50:34Z")

</div>

Sorry, I should say that I am running 1.10.4

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [June 10, 2024, 11:04pm UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/5 "2024-06-10T23:04:46Z")

</div>

Please use triple backticks to quote your code.

````julia
```
# Your code
```

````

---

<div class="post-metadata">

### Author: ![Davidbarber](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Davidbarber](https://discourse.julialang.org/u/Davidbarber)
#### Post date: [June 11, 2024, 9:54am UTC](https://discourse.julialang.org/t/emptying-figures-in-makie/115425/6 "2024-06-11T09:54:55Z")

</div>

To keep things simple, look at the code example in the Makie documentation for IntervalSlider

```julia

using GLMakie #changed from CairoMakie

f = Figure()

#empty!(f)

Axis(f[1, 1], limits = (0, 1, 0, 1))

rs_h = IntervalSlider(f[2, 1], range = LinRange(0, 1, 1000),

startvalues = (0.2, 0.8))

rs_v = IntervalSlider(f[1, 2], range = LinRange(0, 1, 1000),

startvalues = (0.4, 0.9), horizontal = false)

labeltext1 = lift(rs_h.interval) do int

string(round.(int, digits = 2))

end

Label(f[3, 1], labeltext1, tellwidth = false)

labeltext2 = lift(rs_v.interval) do int

string(round.(int, digits = 2))

end

Label(f[1, 3], labeltext2,

tellheight = false, rotation = pi/2)

points = rand(Point2f, 300)

# color points differently if they are within the two intervals

colors = lift(rs_h.interval, rs_v.interval) do h_int, v_int

map(points) do p

(h_int[1] < p[1] < h_int[2]) && (v_int[1] < p[2] < v_int[2])

end

end

scatter!(points, color = colors, colormap = [:gray90, :dodgerblue], strokewidth = 0)

f

```

I have added , but commented out, #empty!(f)

If I run this script (using include in REPL) the results appear in a window. The Sliders work as they should. If I run the script a second time it also works ok.

If I now comment out the f = Figure() line and uncomment the empty!(f) line

```julia

using GLMakie

#f = Figure()

empty!(f)

Axis(f[1, 1], limits = (0, 1, 0, 1))

.

# same code as above

.

f

```

the window appears as before but the Sliders don’t work. They look the same as before but cannot be activated.

I am using Julia 1.10.4

I am relatively new to Makie and cannot see what I need to fix this.

Any ideas?

Thanks
