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.
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
Thanks a lot! However, adding cycle to the plot attributes does not have the desired effect.
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
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.