# How to create a string with observable values in GLMakie?

**URL:** https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525
**Category:** Visualization
**Tags:** question, glmakie, observables
**Created:** [March 12, 2024, 3:37pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525 "2024-03-12T15:37:48Z")
**Posts on this page:** 8
**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: [March 12, 2024, 3:37pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/1 "2024-03-12T15:37:48Z")

</div>

Hello,  
I am using GLMakie to make an interactive plot. I would like to make a label to a slider that shows the actual value of an observable. But how do I extract the value so that it can be rounded and displayed?  
In the example below, I have tried with different combinations, but I always get an error (the third print something bu the value never changes).  
What is the right syntax?  
Thank you

```julia
using GLMakie
# starting parameters
x = 0.1
y = 1.6
z = 1.9
p = [x,y,x]
# ranges
x_vals = LinRange(0,10, 10)
y_vals = LinRange(-2,5, 20)
z_vals = LinRange(-10,10, 100)
# Observable
p_mod = Observable(p)
# plot
fig = Figure()
ax = Axis(fig[1,1:2])
# sliders
Label(fig[2,1], string("X value:", round(p_mod[1], digits=2)))
x_sld = Slider(fig[2,2], range=x_vals, startvalue=x)
Label(fig[3,1], string("Y value:", round(y_sld.value, digits=2)))
y_sld = Slider(fig[3,2], range=x_vals, startvalue=x)
Label(fig[4,1], string("Z value:", round(p_mod.val[3], digits=2)))
z_sld = Slider(fig[4,2], range=x_vals, startvalue=x)
# change values
on(x_sld.value) do val 
    p_mod.val[1] = val 
    p_mod[] = p_mod[]  
end
on(y_sld.value) do val 
    p_mod.val[2] = val 
    p_mod[] = p_mod[]  
end
on(z_sld.value) do val 
    p_mod.val[3] = val 
    p_mod[] = p_mod[]  
end

```

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [March 12, 2024, 4:16pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/2 "2024-03-12T16:16:27Z")

</div>

Try `Label(fig[2,1], @lift string("X value:", round($p_mod[1], digits=2)))`

---

<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: [March 12, 2024, 9:20pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/3 "2024-03-12T21:20:45Z")

</div>

> [@sijo](#):
>
> Label(fig[2,1], @lift string(“X value:”, round($p\_mod[1], digits=2)))

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: [March 12, 2024, 10:05pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/4 "2024-03-12T22:05:51Z")

</div>

Also check SliderGrid which has some good default logic for labeled sliders. Also works for a single one.

[https://docs.makie.org/stable/reference/blocks/slidergrid/](https://docs.makie.org/stable/reference/blocks/slidergrid/)

---

<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: [March 13, 2024, 6:49pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/5 "2024-03-13T18:49:59Z")

</div>

One more thing: is it possible to increase the font size of the label? I tried with:

```julia
julia> Label(fig[2,1], @lift string("X value:", round($p_mod[1], digits=2)), fontsize = 30)
ERROR: syntax: ""X value:"" is not a valid function argument name around /home/gigiux/Documents/Model/testMakie.jl:17
Stacktrace:
 [1] top-level scope
   @ ~/Documents/Model/testMakie.jl:17

julia> Label(fig[2,1], @lift string("X value:", round($p_mod[1], digits=2), fontsize = 30))
ERROR: MethodError: no method matching string(::String, ::Float64; fontsize::Int64)

Closest candidates are:
  string(::Any...) got unsupported keyword argument "fontsize"
   @ Base strings/io.jl:189
  string(::String) got unsupported keyword argument "fontsize"
   @ Base strings/substring.jl:181
  string(::Union{Char, String, Symbol}...) got unsupported keyword argument "fontsize"
   @ Base strings/substring.jl:225
  ...

Stacktrace:
 [1] (::var"#9#10")(arg1#228::Vector{Float64})
   @ Main ./none:0
 [2] #map#13
   @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:570 [inlined]
 [3] map(::var"#9#10", ::Observable{Vector{Float64}})
   @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:568
 [4] top-level scope
   @ ~/Documents/Model/testMakie.jl:17

```

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [March 13, 2024, 7:08pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/6 "2024-03-13T19:08:50Z")

</div>

Try with `@lift(string("X value:", round($p_mod[1], digits=2)))` so that the `@lift` macro doesn’t take the fontsize as argument.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [March 14, 2024, 8:39am UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/7 "2024-03-14T08:39:10Z")

</div>

Also to make the code more readable you can write it on two lines. That also solves the fontsize issue:

```julia
xvalue = @lift string("X value:", round($p_mod[1], digits=2))
Label(fig[2,1], xvalue, fontsize=30)

```

---

<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: [March 15, 2024, 12:28pm UTC](https://discourse.julialang.org/t/how-to-create-a-string-with-observable-values-in-glmakie/111525/8 "2024-03-15T12:28:49Z")

</div>

Thank you!
