Interactive Menu with AlgebraOfGraphics / GLMakie

mreichMPI-BGC
Tue, 31 Jan 2023 22:47:32 +0000
Visualization

Hello,
I am trying to have an interactive AlgebraofGraphics plot, e.g. with a menu to select which variable is plotted.
A MWE is

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

var=Observable("y1")

fig = @lift((data(df) *
    mapping(:x1, Symbol($var), color=:x1) *
    (visual(Scatter) +  smooth(;span=0.3, degree=1)) |> draw).figure)

menu = Menu(fig[], options = ["y1","y2"] , default = "y1")
fig[][1, 3] = vgrid!(
        Label(fig[], "Variable", width = nothing),
        menu,
        tellheight = false, width = 200)

 on(menu.selection) do s
         var[] = s
end

@lift(display($fig))

It is kind of clear that it cannot work, because with fig[] I destroy the observable, but the example shows what I want (it does display the initial figure and also updates, but the menu gets lost).

Is there is a GLMakie expert to help…?

16 posts - 4 participants