Set default color cycle for densities: transparent color and linecolor

I believe I have tried any conceivable combination of cycling arguments to the Theme() object. What I am trying to do:

I have a default color scheme, lets say: default = [:red, :black, :blue]
I want the default behavior of density to be so that I get the color of my colorscheme, transparent by some alpha e.g 0.5, and on top of that I get a line plot with color of my colorscheme.

f = Figure(size = (800, 800))

Axis(f[1, 1], title = "Default cycle palette")

default = [:black, :red, :blue] 
for i in 1:3
    density!(randn(50) .+ 2i;
    # I do not want to have to type this:
    color = (default[i], 0.5), strokewidth = 3, strokecolor = default[i]
)
end

I haven’t been able to achieve this with really 10 different ways of combining cycling arguments both in the palette argument of Theme and also in the Density argument of Theme.

you need to pass it to patch.

pass what to patch?

ax = Axis(fig[1,1]; palette = (; patchcolor = default_colors)) this should work.

And if you are going for the Theme option, also pass this argument.

uhh… well, this also works:

function my_color_theme()
    default_colors = tuple.([:black, :red, :blue], 0.5)
    cycle = Cycle([:color, :linestyle, :strokecolor], covary=true)
    return Theme(
        palette = (; color=default_colors,
            strokecolor=default_colors, linestyle=[:solid]),
        Density=(cycle=cycle,)
        )
end

with_theme(my_color_theme()) do
    f = Figure(size = (800, 800))
    Axis(f[1, 1], title = "Default cycle palette",)
    for i in 1:3
        density!(randn(50) .+ 2i; strokewidth = 3)
    end
    f
end
1 Like

Thank you, this seems to be perfect, I made a small adjustion so that the lines are not transparent:

function my_color_theme()
    default_colors = [:black, :red, :blue]
    default_colors_trans = tuple.(default_colors, 0.5)
    cycle = Cycle([:color, :linestyle, :strokecolor], covary=true)
    return Theme(
        palette = (; color=default_colors_trans,
            strokecolor=default_colors, linestyle=[:solid]),
        Density=(cycle=cycle,)
        )
end

with_theme(my_color_theme()) do
    f = Figure(size = (800, 800))
    Axis(f[1, 1], title = "Default cycle palette",)
    for i in 1:3
        density!(randn(50) .+ 2i; strokewidth = 3)
    end
    f
end