Makie - Weird error with Observables



I am having trouble creating a complete Makie scene that does what I want, because it errors:

ERROR: MethodError: no method matching gl_convert(::String)

I’ll explain what I want first, and then the pieces of code that I have written that (try to) implement it.

What I want

I want to have a scene that contains:

  • 1 general title
  • 3 subplots
  • 1 toggle
  • 1 slider

The slider controls which set of data is chosen. Suppose I have a 1000×3×25 Float64 array. Then the slider controls which set of 1000×3 will be plot (one vector in each subplot).

The toggle will control, in a future, the way the data is displayed. Instead of Float64, there will be complex quantities, and the toggle will select if the modulus is plot or only the real part.

What I have coded

See the 4th post: Makie - Weird error with Observables - #4 by nandoconde

Can you post a minimal working example (MWE) that I can execute and debug?

What is the variable freqs? You have basically left out the most important part :slight_smile: The arguments of the plotting function that errors.

Sorry, I thought the code above was clear enough to guess the rest of the variables.
Here is the state of my packages:

(@v1.6) pkg> st GLMakie
      Status `~\.julia\environments\v1.6\Project.toml`
  [e9467ef8] GLMakie v0.1.27

(@v1.6) pkg> st Colors
      Status `~\.julia\environments\v1.6\Project.toml`
  [5ae59095] Colors v0.12.6

And here is a full MWE:

# Load packages
using GLMakie, Colors

# Data
freqs = range(5e8, 4.5e10, length = 1001);
lr = range(0.01, 2π, length = 1001);
S = Array{Complex,3}(undef, 1001, 3, 25);
for i = 1:25
    S[:,1,i] = @. (50 - 50*exp(im*lr*i/12))/(50 + 50*exp(im*lr*i/12))
    S[:,2,i] = @. (50 - 75*exp(im*lr*i/12))/(50 + 75*exp(im*lr*i/12))
    S[:,3,i] = @. (50 - 35*exp(im*lr*i/12))/(50 + 35*exp(im*lr*i/12))

# Figure
titles = ["S₁₁","S₁₂","S₂₂"]
res = (1920*0.9, 1080*0.5) # Pixel size
fig = Figure(resolution = res)
for i = 1:3
    fig[1,i] = Axis(fig,
    title = titles[i],
    xminorticksvisible = true,
    yminorticksvisible = true,
    xminorgridvisible = true,
    yminorgridvisible = true,
    xminorticks = IntervalsBetween(4),
    yminorticks = IntervalsBetween(4),
    xlabel = "f [GHz]",
    ylabel = "dB")
linkaxes!(contents(fig[1,1])[1], contents(fig[1,2])[1], contents(fig[1,3])[1])
ylims!(contents(fig[1,1])[1], (-50, 0))
fig[0,:] = Label(fig, "Default title", textsize = 30)

# Interactivity
fig[3,:] = Slider(fig, range = 1:25, startvalue = 1)
p = contents(fig[3,:])[1].value
toggle = Toggle(fig, active = true)

# Create labels (static)
lin_label = Label(fig, "lin")
dB_label = Label(fig, "dB")

# Display labels and toggle
fig[2,4] = grid!(hcat(lin_label,toggle,dB_label), tellheight = false)

# Try to plot figures
labels = ["CST","CST","CST"]
colores = [RGB(0.85, 0.325, 0.098), RGB(0, 0.447, 0.741)]
indices = [CartesianIndex(1,1),CartesianIndex(1,2),CartesianIndex(2,2)]
dB = x -> (20*log10(abs(x)))
for i in 1:3
            label = labels[i],
            ylabel = "dB",
            color = colores)

If one only has a few minutes to look into a bug, guessing some variables makes the difference between being able to debug something, or just ignoring the bug report

1 Like

The mwe works, but the line that errors isn’t included

I have removed the original code that I posted because it was a very bad try to make a MWE. The valid MWE is the one I have posted in the 4th post.

I am surprised that it runs for you. I have copypasted the code I wrote here in the 4th post to my Julia 1.6.0 REPL and it errors. I have recorded a video where I literally copypaste it into a newly created REPL. I could post it here if it helps, but I don’t know how to do that.

I am a bit lost right now :sweat_smile:

Ok, funny, it doesn’t reproduce in VSCode but in the repl! Nevermind then :wink:

Oh I remember something, I got the same error with label = “some string” before I excluded the label keyword from conversion in GLMakie. Maybe your version is just too old, it’s definitely not the latest from the 0.1 range

So there is no ylabel for lines - you need to do axis = (ylabel = ...,))!

for i in 1:3
        label = labels[i],
        axis = (ylabel="dB",),
        color = colores[1])

Note, that colores is a 2 element array while dB.(S[:,i,1]) is a 1001 element array… You need either 1 color per line, or 1 color per coordinate!
The errors are pretty horrible though - I think that may just be one of the next projects to improve in Makie!

But you can’t set the ylabel when plotting into an existing axis. Only the plotting functions without ! that create a new axis take axis parameters.

Thanks! This solved it. I have more questions, but I will post them in a different thread because they are unrelated to this exact problem.