# Set default color cycle for densities: transparent color and linecolor

**URL:** <https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [May 10, 2024, 11:00am UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097 "2024-05-10T11:00:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 10, 2024, 11:00am UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/1 "2024-05-10T11:00:04Z")

</div>

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.

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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/d/0df606a22fd9f718ac54b285cbcd1ca42fa633f6.png)

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

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [May 10, 2024, 1:17pm UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/2 "2024-05-10T13:17:45Z")

</div>

you need to pass it to `patch`.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 10, 2024, 1:27pm UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/3 "2024-05-10T13:27:03Z")

</div>

pass **what** to patch?

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [May 10, 2024, 1:32pm UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/4 "2024-05-10T13:32:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [May 10, 2024, 1:50pm UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/5 "2024-05-10T13:50:21Z")

</div>

uhh… well, this also works:

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

```

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 10, 2024, 2:21pm UTC](https://discourse.julialang.org/t/set-default-color-cycle-for-densities-transparent-color-and-linecolor/114097/6 "2024-05-10T14:21:20Z")

</div>

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

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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/b/1b62bc502a88089350a80117c99bce655776fb96.jpeg)
