Saving GLMakie figure without widgets

Hi,
Is there any way to save GLMakie figure without buttons/sliders?
MWE:

p = Figure(size=(500, 500))
ax = Axis(p[1, 1])
b = Button(p[2, 1], label="button", tellwidth=false)
GLMakie.scatter!(1, 1)
GLMakie.save("test.png", p)

using GLMakie.save("test.png", p[1, 1]) throws

┌ Warning: Mapping to the storage type failed; perhaps your data had out-of-range values?
│ Try `map(clamp01nan, img)` to clamp values to a valid range.
└ @ ImageMagick ~/.julia/packages/ImageMagick/KkM1b/src/ImageMagick.jl:180
Errors encountered while save FileIO.File{FileIO.DataFormat{:PNG}, String}("test.png").
All errors:
===========================================
MethodError: no method matching save(::FileIO.File{FileIO.DataFormat{:PNG}, String}, ::GridPosition)
The function `save` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  save(::FileIO.File{FileIO.DataFormat{:PNG}}, ::S; kwargs...) where {T, S<:Union{AbstractArray{T, 3}, AbstractMatrix}}
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:71
  save(::FileIO.File{FileIO.DataFormat{:EXR}}, ::Any...; kwargs...)
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:143
  save(::FileIO.File{FileIO.DataFormat{:QOI}}, ::Any...; kwargs...)
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:154
  ...

===========================================
MethodError: no method matching length(::GridPosition)
The function `length` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  length(::Distributions.VonMisesFisherSampler)
   @ Distributions ~/.julia/packages/Distributions/psM3H/src/samplers/vonmisesfisher.jl:20
  length(::MathOptInterface.Bridges.Constraint.Map)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/03Qtw/src/Bridges/Constraint/map.jl:50
  length(::Automa.ActionList)
   @ Automa ~/.julia/packages/Automa/EyNRt/src/action.jl:64
  ...

===========================================
ArgumentError: Package OpenCV [f878e3a2-a245-4720-8660-60795d644f2a] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

===========================================
ArgumentError: Argument does not support conversion to png.
===========================================

Fatal error:
ERROR: MethodError: no method matching save(::FileIO.File{FileIO.DataFormat{:PNG}, String}, ::GridPosition)
The function `save` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  save(::FileIO.File{FileIO.DataFormat{:PNG}}, ::S; kwargs...) where {T, S<:Union{AbstractArray{T, 3}, AbstractMatrix}}
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:71
  save(::FileIO.File{FileIO.DataFormat{:EXR}}, ::Any...; kwargs...)
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:143
  save(::FileIO.File{FileIO.DataFormat{:QOI}}, ::Any...; kwargs...)
   @ ImageIO ~/.julia/packages/ImageIO/Fs42T/src/ImageIO.jl:154
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[255]:1
Stacktrace:
 [1] top-level scope
   @ REPL[255]:1

I think there’s a colorbuffer(::Axis) method for that purpose

1 Like

Thanks! It works. But it doesn’t work for Axis3

p = Figure(size=(500, 500))
ax = Axis3(p[1, 1])
b = Button(p[2, 1], label="button", tellwidth=false)
GLMakie.scatter!(1, 1, 1)
GLMakie.save("test.png", colorbuffer(ax))
ERROR: MethodError: no method matching colorbuffer(::Axis3)
The function `colorbuffer` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  colorbuffer(::Axis; include_decorations, update, colorbuffer_kws...)
   @ Makie ~/.julia/packages/Makie/Vn16E/src/makielayout/blocks/axis.jl:1982
  colorbuffer(::GLMakie.Screen; ...)
   @ GLMakie ~/.julia/packages/GLMakie/vdrwE/src/screen.jl:887
  colorbuffer(::GLMakie.Screen, ::Makie.ImageStorageFormat; figure)
   @ GLMakie ~/.julia/packages/GLMakie/vdrwE/src/screen.jl:887
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[265]:1