Interactive Menu with AlgebraOfGraphics / GLMakie

This one works, if you are only using 1 Axis

using AlgebraOfGraphics, GLMakie
using DataFrames

x1=rand(50)
y1=10x1.^2
y2=x1 .+ randn(50)
df = DataFrame((;x1, y1, y2))

var=Observable("y1")
fig=Figure()

axentry = draw!(fig[1,1:1], data(df) * 
    mapping(:x1, Symbol(var[]), color=:x1) * 
    (visual(Scatter) +  smooth(;span=0.3, degree=1)))
Colorbar(fig[:, 2])

menu = Menu(fig, options = ["y1","y2"] , default = "y1")
fig[2,1] = hgrid!(
        Label(fig, "Variable", width = nothing),
        menu,
        tellheight = true)
    
 on(menu.selection) do s
         var[] = s
         Makie.delete!(fig.current_axis[])
         draw!(fig[1,1], data(df) * 
    mapping(:x1, Symbol(s), color=:x1) * 
    (visual(Scatter) +  smooth(;span=0.3, degree=1)))
end
fig

For more complicated layouts we will need a list of all Axis plotted. @jules how do we get the axis being plotted at fig[1,1]) ?

1 Like