# How to add button to GLMakie plot?

**URL:** <https://discourse.julialang.org/t/how-to-add-button-to-glmakie-plot/124649>\
**Category:** New to Julia\
**Created:** [January 10, 2025, 4:29pm UTC](https://discourse.julialang.org/t/how-to-add-button-to-glmakie-plot/124649 "2025-01-10T16:29:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [January 10, 2025, 4:29pm UTC](https://discourse.julialang.org/t/how-to-add-button-to-glmakie-plot/124649/1 "2025-01-10T16:29:18Z")

</div>

I would like to add a button to a plot made with GLMakie; it looks straightforward but I get an error:

```julia
julia> using GLMakie

julia> xs = range(0, 10, length = 30)
0.0:0.3448275862068966:10.0

julia> ys = 0.5 .* sin.(xs)
30-element Vector{Float64}:
  0.0
  0.16901720891675515
  0.31813559874072506
  0.4297990881620116
  ⋮
  0.05709177372417583
 -0.11418078572148098
 -0.2720105554446849

julia> fig = scatter(xs, ys)

julia> fig[2,1] = buttongrid = GridLayout(tellwidth = false)
ERROR: MethodError: no method matching setindex!(::Makie.FigureAxisPlot, ::GridLayout, ::Int64, ::Int64)
The function `setindex!` exists, but no method is defined for this combination of argument types.
Stacktrace:
 [1] top-level scope
   @ ~/Documents/Model/testButton.jl:5

julia> buttons = buttongrid[1,1] = [
           Button(fig, label = "BUTTON", fontsize = 18)
       ]
ERROR: MethodError: no method matching _block(::Type{Button}, ::Makie.FigureAxisPlot; label::String, fontsize::Int64)
The function `_block` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  _block(::Type{<:Makie.Block}, ::Union{Figure, Scene}, ::Any, ::Dict, ::Any; kwdict_complete) got unsupported keyword arguments "label", "fontsize"
   @ Makie ~/.julia/packages/Makie/Y3ABD/src/makielayout/blocks.jl:317
  _block(::Type{<:Makie.Block}, ::Union{Figure, Scene}, Any...; bbox, kwargs...)
   @ Makie ~/.julia/packages/Makie/Y3ABD/src/makielayout/blocks.jl:261
  _block(::Type{<:Makie.Block}, ::Union{GridPosition, GridSubposition}, Any...; kwargs...)
   @ Makie ~/.julia/packages/Makie/Y3ABD/src/makielayout/blocks.jl:249

Stacktrace:
 [1] Button(args::Makie.FigureAxisPlot; kwargs::@Kwargs{label::String, fontsize::Int64})
   @ Makie ~/.julia/packages/Makie/Y3ABD/src/makielayout/blocks.jl:240
 [2] top-level scope
   @ ~/Documents/Model/testButton.jl:6

```

How can I properly place a button?

Thank you

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 10, 2025, 4:40pm UTC](https://discourse.julialang.org/t/how-to-add-button-to-glmakie-plot/124649/2 "2025-01-10T16:40:46Z")

</div>

You need to do `fig, ax, sc = scatter` so that fig is actually a Figure

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [January 11, 2025, 5:02pm UTC](https://discourse.julialang.org/t/how-to-add-button-to-glmakie-plot/124649/3 "2025-01-11T17:02:28Z")

</div>

Thank you, it did work:

```julia
using GLMakie
xs = range(0, 10, length = 30)
ys = 0.5 .* sin.(xs)
fig = Figure()
ax = Axis(fig[1,1], title = "Example", ylabel = "Y", xlabel = "X")
sc = scatter
lines!(ax, xs, ys, linewidth = 5, color =:midnightblue)
fig[2,1] = buttongrid = GridLayout(tellwidth = false)
buttons = buttongrid[1,1] = [
    Button(fig, label = "Save Figure", fontsize = 18)
]

```
