# Plots - reset color cycle

**URL:** <https://discourse.julialang.org/t/plots-reset-color-cycle/74751>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [January 17, 2022, 10:08am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751 "2022-01-17T10:08:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cripcate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cripcate/32/34170_2.png) [@cripcate](https://discourse.julialang.org/u/cripcate)\
**Post date:** [January 17, 2022, 10:08am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/1 "2022-01-17T10:08:50Z")

</div>

Hi there. I have a plot with two different series (a scatterline and a fillrange). I want the fillrange (representing error) to be of the same color as the line.

Here is my code:

```julia
using DataFrames, Plots, Random
Random.seed!(12345)

test_data = DataFrame(
                [1:100, rand(100), sample(['A', 'B',], 100)],
                [:Image_no, :val1, :category]
            )
test_data.val_lo = test_data.val1 .- 0.1
test_data.val_hi = test_data.val1 .+ 0.1;

first(test_data, 5)

```

```julia
5 rows × 5 columns

Image_no	val1	category	val_lo	val_hi
Int64	Float64	Char	Float64	Float64
1	1	0.791805	B	0.691805	0.891805
2	2	0.159579	A	0.059579	0.259579
3	3	0.334191	B	0.234191	0.434191
4	4	0.811392	B	0.711392	0.911392
5	5	0.796629	A	0.696629	0.896629

```

```julia
plot(
    test_data.Image_no, test_data.val1, group=test_data.category,
    marker=:o, lw=1.5,
)
plot!(
    test_data.Image_no, test_data.val_lo, group=test_data.category,
    fillrange=test_data.val_hi,
    alpha=0.5, 
)

```

 ![testplot](https://global.discourse-cdn.com/julialang/original/3X/c/7/c708d9ec01542333a29b6fc29f00da570ed10e2f.png)

Plots.jl uses the next colors of the color cycle of the palette for the fillranges, so that the colors do not match with those of the scatterline.

I have tried using different colors for the `color` or `seriescolor` arguments. For example I tried `[1, 2]` to select the first two colors of the palette, or i tried

```julia
using ColorSchemes

colors = ColorSchemes.tab10[1:2]

plot(..., color_palette=colors)

```

But none of this leads to my desired output (fillrange and line of the same color, but cycling through colors for each category).

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 17, 2022, 10:51am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/2 "2022-01-17T10:51:16Z")

</div>

If you add argument: `color=[:red :blue]`, to both plot commands, the desired result will be obtained. Maybe you can generalize this idea.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 17, 2022, 11:17am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/3 "2022-01-17T11:17:16Z")

</div>

You might be able to make use of the `ribbon` keyword:

```julia
plot(
    test_data.Image_no, test_data.val1, group=test_data.category,
    marker=:o, lw=1.5,
    ribbon=(test_data.val1-test_data.val_lo, test_data.val1+test_data.val_hi),
)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 17, 2022, 11:37am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/4 "2022-01-17T11:37:25Z")

</div>

@baggepinnen, just a minor typo on the second difference:  
`ribbon=(test_data.val1 - test_data.val_lo, test_data.val_hi - test_data.val1)`

---

<div class="post-metadata">

**Author:** ![cripcate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cripcate/32/34170_2.png) [@cripcate](https://discourse.julialang.org/u/cripcate)\
**Post date:** [January 17, 2022, 11:45am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/5 "2022-01-17T11:45:05Z")

</div>

Thanks for the help.

@rafael.guerra : If I use `color=[:red, :blue]`, plots will alternate between red and blue for each datapoint of the individual series, leading to red(blue stripes in both series. If I use `palette=[:red, :blue]`, I get my desired output (I guess because this changes the palette not the individual series color). This works with named colors as well as with `ColorSchemes.jl`, e.g., `..., palette=ColorSchemes.tab10[1:2]`

@baggepinnen : Yes, I think the `ribbon` keyword works nicely in this case, because it reduces everything to one plot call so that Plots will a,lways cycle the colors correctly I think.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 17, 2022, 11:46am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/6 "2022-01-17T11:46:05Z")

</div>

> [@cripcate](#):
>
> `color=[:red, :blue]`

That is not what was written, but `color=[:red :blue]`

Note that in `Plots.jl`, the difference betwen vectors and matrices is crucial.

---

<div class="post-metadata">

**Author:** ![cripcate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cripcate/32/34170_2.png) [@cripcate](https://discourse.julialang.org/u/cripcate)\
**Post date:** [January 17, 2022, 11:49am UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/7 "2022-01-17T11:49:01Z")

</div>

Ahhh, yes indeed. Now I also remember reading an article in the docs of Plots.jl explaining exactly this difference. Sorry!

`[:red :blue]` (1x2 Matrix) will cycle through red and blue for series.

`[:red, :blue]` (2 element Vector) will use both colors for one series.

Thanks!

**EDIT:** Here is the corresponding section from the [Plots.jl](https://docs.juliaplots.org/stable/input_data/#columns-are-series) documentation.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 17, 2022, 12:41pm UTC](https://discourse.julialang.org/t/plots-reset-color-cycle/74751/8 "2022-01-17T12:41:17Z")

</div>

This generalizes a bit my comment further above:

```julia
n = length(unique(test_data.category))
colors = palette(:default)[1:n]'

```

then just add the following argument to the plots commands:

```julia
 color=colors

```
