Hlines!() xmin/xmax do not accept Observable list in GLMakie

I’m trying to plot horizontal (or vertical) lines using GLMakie, but I need both the lines and the endpoints to be an Observable of a list. I want to do something very similar to the documentation for hlines and vlines, reproduced here

hlines!(ax2, [1, 2, 3, 4], xmax = [0.25, 0.5, 0.75, 1], color = :blue)

but with xmax and xmin to be Observables, like this:

hlines!(ax2, Observable([1, 2, 3, 4]), xmax = Observable([0.25, 0.5, 0.75, 1]), color = :blue)

The example in the docs uses CairoMakie, and this works fine. But I found that not only does an Observable of a list (e.g. Observable([0.25, 0.5, 0.75, 1])) not work for xmax or xmin, but even a plain list will not work in GLMakie. The error is the same in both cases:

ERROR: MethodError: no method matching gl_convert(::Vector{Float64})

Is there a reason this doesn’t work in GLMakie, or a different way to do it?
A workaround I’m trying is to iterate through lists of Observables representing xmin, xmax, and the height, and do one line at a time, but the code is getting quite cumbersome.

Things that do work:

  • Lines that are an Observable list, no min/max:

hlines!(Observable([0.25, 0.5, 0.75, 1])

  • Single values, where xmin, xmax, or both are Observables:

hlines!(1.0, xmin = Observable(0.2), xmax = Observable(0.75))

Extra info
The application I’m working on for this is to show energy levels in a Morse potential, but the function that generates the energy levels will respond to the Observable updates. The curve with get wider and narrower with the Sliders, so the endpoints of the horizontal lines must change with the graph. The height of the hlines will also change when the sliders are adjusted.

This PR should fix it:
https://github.com/MakieOrg/Makie.jl/compare/sd/fix-hvlines?expand=1

In the future, it would be better to open these as issues on github.
I visit github way more often than discourse, and I also look at it way less thoroughly, making it pure luck if I see your issue report here :wink:

Ok! I wasn’t sure if it was a bug, or if I was doing it wrong. I’ll open an issue in the future.

1 Like