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

**URL:** <https://discourse.julialang.org/t/hlines-xmin-xmax-do-not-accept-observable-list-in-glmakie/90788>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [November 25, 2022, 4:21am UTC](https://discourse.julialang.org/t/hlines-xmin-xmax-do-not-accept-observable-list-in-glmakie/90788 "2022-11-25T04:21:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)\
**Post date:** [November 25, 2022, 4:21am UTC](https://discourse.julialang.org/t/hlines-xmin-xmax-do-not-accept-observable-list-in-glmakie/90788/1 "2022-11-25T04:21:24Z")

</div>

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`](https://docs.makie.org/v0.18.3/examples/plotting_functions/hvlines/index.html), reproduced here

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

```

but with `xmax` and `xmin` to be `Observable`s, like this:

```julia
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:

```julia
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 `Observable`s:

`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.

 ![Screenshot 2022-11-25 at 13.20.20](https://global.discourse-cdn.com/julialang/original/3X/6/1/6106a99fa4687e4878dfedde6ed543b616adc194.png)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 25, 2022, 12:20pm UTC](https://discourse.julialang.org/t/hlines-xmin-xmax-do-not-accept-observable-list-in-glmakie/90788/2 "2022-11-25T12:20:19Z")

</div>

This PR should fix it:  
[https://github.com/MakieOrg/Makie.jl/compare/sd/fix-hvlines?expand=1](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 😉

---

<div class="post-metadata">

**Author:** ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)\
**Post date:** [November 25, 2022, 9:26pm UTC](https://discourse.julialang.org/t/hlines-xmin-xmax-do-not-accept-observable-list-in-glmakie/90788/3 "2022-11-25T21:26:58Z")

</div>

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.
