Save main scene (with axis ticks and spines) to file without closing current window

The following works more or less. But, it will be better to actually save the scene with all the spines and ticks values, plus the window is closing when I hit the button save. Any suggestions?

using GLMakie
with_theme(theme_minimal()) do 
    fig = Figure()
    menu = Menu(fig, options = ["save to file"])
    menu2 = Menu(fig, options = ["Spectral_11", "viridis", "heat"])    
    ax = Axis(fig[1, 1])
    toggles = [Toggle(fig, active = active) for active in [true, false]]
    labels = [Label(fig, lift(x -> x ? "$l visible" : "$l invisible", t.active))
        for (t, l) in zip(toggles, ["sine", "cosine"])]

    fig[1, 2] = grid!(hcat(toggles, labels), tellheight = false)

    line1 = lines!(0..10, sin, color = :blue, visible = false)
    line2 = lines!(0..10, cos, color = :red)
    pltobj = heatmap!(1:3, 0:0.1:0.5, rand(3,5))
    fig[1, 0] = vgrid!(
        Label(fig, "Save ?", width = nothing), menu, 
        Label(fig, "colormap", width = nothing), menu2; tellheight = false, width = 200)
    on(menu.selection) do s
        save("testFile.png", ax.scene, resolution = (1900,800)) # not good, axis are gone 
    end
    on(menu2.selection) do s
        pltobj.colormap = s
    end
    connect!(line1.visible, toggles[1].active)
    connect!(line2.visible, toggles[2].active)
    fig
end
1 Like

The internal axis scene just doesn’t contain the axis spines etc, that’s why they’re missing if you save it like that. I’m not sure that what you wish for can work currently, as you can’t transplant an existing axis into a second figure either.

Is there a way to save without closing the plot window?
This occurs in Win10 for save arguments: ax.scene or fig.

2 Likes

+1 about the window closing when the save button is clicked.

System: Windows 11, GLMakie 0.8.2 (with Makie 0.19.2 and MakieCore 0.6.2 installed as deps). Sometimes there’s an error about the inability to keep the window content current (or something along these lines), but mostly it just fails silently.