# Makie recipe and cycle colour

**URL:** <https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910>\
**Category:** Visualization\
**Tags:** makie, recipe\
**Created:** [October 6, 2025, 8:03am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910 "2025-10-06T08:03:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthiasbaitsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthiasbaitsch/32/214952_2.png) [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Post date:** [October 6, 2025, 8:03am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/1 "2025-10-06T08:03:28Z")

</div>

What is a good way to cycle through plot attributes in a recipe? In the example below, the first plot should use the same colours as second.

```julia-auto
using Makie
using CairoMakie

# Recipe
@recipe TestPlot begin end

function Makie.plot!(p::TestPlot)
    for _ = 1:p.args[][1]
        lines!(p, rand(5))
    end
    return p
end

# Plot with and without recipe
fig = Figure()
Axis(fig[1, 1])
testplot!(10)
Axis(fig[2, 1])
for _ = 1:10
    lines!(rand(5))
end
fig

```

 ![plot_72](https://global.discourse-cdn.com/julialang/original/3X/e/9/e9b62159f3736df74eb5106dc395b695ad51c65d.png)

---

<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:** [October 6, 2025, 9:05am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/2 "2025-10-06T09:05:53Z")

</div>

You have to declare which attributes to cycle in the theme via `cycle = [:color]` and similar, compare with [Code search results · GitHub](https://github.com/search?q=repo%3AMakieOrg%2FMakie.jl+%22cycle+%3D+%22&type=code)

---

<div class="post-metadata">

**Author:** ![matthiasbaitsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthiasbaitsch/32/214952_2.png) [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Post date:** [October 6, 2025, 9:53am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/3 "2025-10-06T09:53:39Z")

</div>

Thanks a lot! However, adding cycle to the plot attributes does not have the desired effect.

```julia-auto
using Makie
using CairoMakie

# Recipe
@recipe TestPlot begin
    cycle = [:color]
end

function Makie.plot!(p::TestPlot)
    for _ = 1:p.args[][1]
        lines!(p, rand(5))
    end
    return p
end

# Plot with and without recipe
fig = Figure()
Axis(fig[1, 1])
testplot!(10)
Axis(fig[2, 1])
for _ = 1:10
    lines!(rand(5))
end
fig

```

 ![plot_88](https://global.discourse-cdn.com/julialang/original/3X/a/0/a021320b0a443208b6ad40c41a23e90b2b13c597.png)

---

<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:** [October 6, 2025, 10:17am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/4 "2025-10-06T10:17:23Z")

</div>

Ah I didn’t read your recipe right, you’re looping inside it. Cycling only works on the level of the plot object, not its nested parts. The cycler doesn’t see your inner lines, it just gives `testplot` a cycled color (if you declare it as an attribute).

In such a case it would be better to define a colormap attribute and then assign the colors using that. And it’s generally more performant if you merge your lines objects into a single NaN gapped one, especially if there are many lines.

---

<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:** [October 6, 2025, 10:35am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/5 "2025-10-06T10:35:02Z")

</div>

You could also do:

```julia
function Makie.plot!(p::TestPlot)
    for i = 1:p.args[][1]
        lines!(p, rand(5), color=Cycled(i))
    end
    return p
end

```

---

<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:** [October 6, 2025, 10:35am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/6 "2025-10-06T10:35:44Z")

</div>

oh really that works within recipes now?

---

<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:** [October 6, 2025, 10:50am UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/7 "2025-10-06T10:50:02Z")

</div>

Yes…and the recipe should actually also work!  
I think its a problem in the cycle index here:

> <https://github.com/MakieOrg/Makie.jl/blob/master/Makie/src/compute-plots.jl#L754C10-L777>

---

<div class="post-metadata">

**Author:** ![matthiasbaitsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthiasbaitsch/32/214952_2.png) [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Post date:** [October 6, 2025, 1:08pm UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/8 "2025-10-06T13:08:38Z")

</div>

Great, that does the job for now, thanks a lot!

---

<div class="post-metadata">

**Author:** ![matthiasbaitsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthiasbaitsch/32/214952_2.png) [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Post date:** [October 6, 2025, 1:10pm UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/9 "2025-10-06T13:10:18Z")

</div>

It actually worked like that some time ago.

---

<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:** [October 6, 2025, 1:11pm UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/10 "2025-10-06T13:11:31Z")

</div>

can you open an issue with this as a regression, so we dont forget about it?

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [October 6, 2025, 2:49pm UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/11 "2025-10-06T14:49:12Z")

</div>

> [@sdanisch](#):
>
> ```julia-auto
> function Makie.plot!(p::TestPlot)
> for i = 1:p.args[][1]
> lines!(p, rand(5), color=Cycled(i))
> end
> return p
> end
> 
> ```

Would it actually cycle the “global” cycler? Ie, if I do `testplot(...)` and then `lines!`, would `lines!` use the next color in the cycler?

---

<div class="post-metadata">

**Author:** ![matthiasbaitsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthiasbaitsch/32/214952_2.png) [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Post date:** [October 6, 2025, 3:05pm UTC](https://discourse.julialang.org/t/makie-recipe-and-cycle-colour/132910/12 "2025-10-06T15:05:37Z")

</div>

Of course, I just filed [#5322](https://github.com/MakieOrg/Makie.jl/issues/5322).
