# Proper order when cycling through colormap

**URL:** https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209
**Category:** Visualization
**Tags:** makie, cairomakie
**Created:** [June 25, 2024, 2:49pm UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209 "2024-06-25T14:49:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![erathorn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erathorn/32/27641_2.png) [@erathorn](https://discourse.julialang.org/u/erathorn)
#### Post date: [June 25, 2024, 2:49pm UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/1 "2024-06-25T14:49:44Z")

</div>

Using this (slightly adapted) code from the documentation, we can see, that the cycler, uses the two extreme colors from the colormap.

```julia
using CairoMakie

categories = rand(1:3, 1000)
values = randn(1000)
dodge = rand(1:2, 1000)
theme = Attributes(colormap=:bluesreds)
with_theme(theme) do
CairoMakie.boxplot(categories, values, dodge = dodge, show_notch = true, color = dodge)
end

```

 ![example](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f57837565bcecad5264242a13cfa7d26175bed0.png)

However, I would like to have the first two colors of my colormap used by the function. Any ideas and suggestions on how I can achieve this?

---

<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: [June 25, 2024, 3:27pm UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/2 "2024-06-25T15:27:32Z")

</div>

You need to set colorrange to `(1, n)` where n is the number of colors in the colormap

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [June 25, 2024, 3:34pm UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/3 "2024-06-25T15:34:28Z")

</div>

```julia
Mke.boxplot(categories, values, dodge=dodge, colormap=:bluesreds, colorrange=[1,8], show_notch = true, color=dodge)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/e/5e3f0483ff72b589a705a4afce7e79561c0a00ba.png)

(Edit: Too slow!)

---

<div class="post-metadata">

### Author: ![erathorn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erathorn/32/27641_2.png) [@erathorn](https://discourse.julialang.org/u/erathorn)
#### Post date: [June 26, 2024, 5:23am UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/4 "2024-06-26T05:23:11Z")

</div>

These solutions do not help with coloring the outliers properly. They are still in their “original” color scheme. Additionally, is there a solution, where I can apply this systematically to an entire figure, instead of setting it manually for each subplot?

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [June 26, 2024, 9:42am UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/5 "2024-06-26T09:42:34Z")

</div>

Well the documentation [here](https://docs.makie.org/stable/reference/plots/boxplot) seems to say that you should use

```julia
outliercolor=dodge

```

> Colors are customizable. The `color` attribute refers to the color of the boxes, whereas `outliercolor` refers to the color of the outliers. If not scalars (e.g. `:red` ), these attributes must have the length of the data. If `outliercolor` is not provided, outliers will have the same color as their box, as shown above.

but it doesn’t seem to work like this for me when I try it.

On the other hand, if I try `outliercolor=:red`, this works as expected. It is as if `outliercolor` ignores the `colormap`.

---

<div class="post-metadata">

### Author: ![erathorn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erathorn/32/27641_2.png) [@erathorn](https://discourse.julialang.org/u/erathorn)
#### Post date: [July 1, 2024, 7:44am UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/6 "2024-07-01T07:44:49Z")

</div>

`outliercolor` definitely seems to ignore the colormap, unless you pass it as part of the theme.

However, if you can get access to the colors you want in a vector, you can apparently do the following:

```julia
csheme = to_colormap(:bluesreds)
f = CairoMakie.boxplot(categories, values, dodge = dodge, show_notch = true,
        color = getindex.(Ref(csheme), dodge), 
        outliercolor=getindex.(Ref(csheme), dodge)
        )

```

 ![display](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f5c5380205363f84abc2471c7089fbf6b8accdd.png)

Not very elegant, but functional.

---

<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: [July 1, 2024, 12:30pm UTC](https://discourse.julialang.org/t/proper-order-when-cycling-through-colormap/116209/7 "2024-07-01T12:30:46Z")

</div>

Could probably be fixed by forwarding the colormap to the internal scatter plot
