Emptying figures in makie

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.

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

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

Sorry, I should say that I am running 1.10.4

Please use triple backticks to quote your code.

```
# Your code
```

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 f = 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 using Julia 1.10.4

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

Any ideas?

Thanks