# Makie.jl Series Plot Color Cycling with Observable Legends

**URL:** <https://discourse.julialang.org/t/makie-jl-series-plot-color-cycling-with-observable-legends/114599>\
**Category:** Visualization\
**Created:** [May 23, 2024, 2:26am UTC](https://discourse.julialang.org/t/makie-jl-series-plot-color-cycling-with-observable-legends/114599 "2024-05-23T02:26:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew3245](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@matthew3245](https://discourse.julialang.org/u/matthew3245)\
**Post date:** [May 23, 2024, 2:26am UTC](https://discourse.julialang.org/t/makie-jl-series-plot-color-cycling-with-observable-legends/114599/1 "2024-05-23T02:26:07Z")

</div>

My goal is to plot a series of data and have their legends be observable so I can change them later. This works already using `series!` using the `labels` keyword argument set to a vector of observables. However, when I add another series plot on top of an existing one, the colors seem to repeat themselves (they do not cycle).

Consider the following example which illustrates this:

```julia
using GLMakie

fig = Figure()
ax = Axis(fig[1, 1])

# Labels I want to change
lab1 = Observable("label 1")
lab2 = Observable("label 2")
lab3 = Observable("label 3")
lab4 = Observable("label 4")

# Arbitrary data to plot
X = [1, 2, 3]
Y1 = [1 2 3; 4 5 6] # First set of Y data
Y2 = [2 5 7; 3 1 9] # Second set of Y data

# Plot Y1 using series plot
series!(ax, X, Y1, labels=[lab1, lab2])

# Plot Y2 on top of current axis
series!(ax, X, Y2, labels=[lab4, lab4])
axislegend(ax)
fig

```

 ![Screenshot from 2024-05-23 12-12-55](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4af1b62607e505d671d7f2cd68653abe22c564c.png)

Here I can successfully change `lab1`, `lab2`, `lab3` and `lab4` to different strings and the legend updates appropriately. The problem is the colors of the lines repeat themselves.

Below is an alternative approach which uses the `lines!` function instead of `series!` to get proper color cycling:

```julia
# Plot Y1 using line plot
foreach((y, lab) -> lines!(ax, X, y, label=lab), eachrow(Y1), [lab1, lab2])

# Plot Y2 on top of current axis
foreach((y, lab) -> lines!(ax, X, y, label=lab), eachrow(Y2), [lab3, lab4])
axislegend(ax)
fig

```

 ![Screenshot from 2024-05-23 12-12-46](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c631559ddbd18676abb63f6baa9f3436850a723.png)

Here the colors work better, however, I can no longer change the labels.

Does anyone have an idea what the best approach would be for me to use? I did read this discussion:

> [@Makie : Update plot legend through Observables](https://discourse.julialang.org/t/makie-update-plot-legend-through-observables/86786):
>
> Hello, I am trying to a basic app with GLMakie with some user input. The (scatter) plot nicely updates with a slider which basically selects which dots to plots but I can’t seem to find a way to update the legend (through either axislegend or Legend) on the fly. Is there a way to do this? Would you have an example? Thanks a lot!

But I was wondering if there was a more elegant solutions than this? Any help is appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![csoto3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csoto3/32/219254_2.png) [@csoto3](https://discourse.julialang.org/u/csoto3)\
**Post date:** [January 14, 2025, 11:42pm UTC](https://discourse.julialang.org/t/makie-jl-series-plot-color-cycling-with-observable-legends/114599/2 "2025-01-14T23:42:54Z")

</div>

Bumping this thread as I’m facing the same exact issue. I also read through and posted in discussion that is referenced above.
