# Way to get default color order in Plots.jl?

**URL:** <https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643>\
**Category:** General Usage\
**Tags:** question, plotting, plots\
**Created:** [July 25, 2018, 12:55am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643 "2018-07-25T00:55:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [July 25, 2018, 12:55am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/1 "2018-07-25T00:55:43Z")

</div>

If you’re using `pgfplots()` through `Plots.jl` the colors are not the obvious ones you think they would be (i.e. `:blue`, `:red`, `:green`)?

Is there a way to get the default color order within the `Plots.jl` framework?

* * *

By picture, notice the two are different. I want to be able to pipe in the `blue` and `red` colors from the left one.

 ![59%20PM](https://global.discourse-cdn.com/julialang/original/3X/9/3/93da72b8e9ff70bf381c9a25753fce9736c8c43c.png)

// **edit:** does it come from Colors.jl?

* * *

also can you do a matlab style `hold on` to keep the color from rotating so you can make multiple `plot!` calls?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [July 25, 2018, 4:40pm UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/2 "2018-07-25T16:40:33Z")

</div>

Closing this. For future readers, the answer is:

```julia
get_color_palette(:auto, plot_color(:white), 17)

```

* * *

As in,

```julia
cur_colors = get_color_palette(:auto, plot_color(:white), 17)
pp = linspace(0,1)

plot()
for (cur_index, cur_color) in enumerate(cur_colors[1:7])
    plot!(pp, 0+pp+cur_index-7)
end
for (cur_index, cur_color) in enumerate(cur_colors[1:7])
    plot!(pp, 1-pp+cur_index-7, color=cur_color)
end
plot!()

```

 ![09%20PM](https://global.discourse-cdn.com/julialang/original/3X/f/0/f077d0caada6e0de80dcc683f7baddbc7cea4052.png)

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [July 25, 2018, 8:01pm UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/3 "2018-07-25T20:01:38Z")

</div>

You can simply pass an integer `i` as the argument to `color` to select the `i`th default color. So this is equivalent to your code:

```julia
pp = [0,1]
plot()
for i = 1:7
    plot!(pp, 0+pp+i-7)
end
for i = 1:7
    plot!(pp, 1-pp+i-7, color=i)
end
plot!()

```

I think this is still undocumented.

---

<div class="post-metadata">

**Author:** ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)\
**Post date:** [July 25, 2018, 9:56pm UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/4 "2018-07-25T21:56:09Z")

</div>

Different [PlotThemes](https://github.com/JuliaPlots/PlotThemes.jl) have different color palettes. You get the the color palette of a theme with `palette(thm::Symbol)`, so for the default theme this would be `palette(:default)`.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [March 23, 2021, 6:21am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/5 "2021-03-23T06:21:07Z")

</div>

This answer appears to be outdated. `get_color_palette(:auto, plot_color(:white), 17)` gives me

```julia
MethodError: no method matching get_color_palette(::Symbol, ::RGBA{Float64}, ::Int64)
Closest candidates are:
  get_color_palette(::Any, ::Any) at C:\Users\Max\.julia\packages\PlotUtils\es5pb\src\colorschemes.jl:325
  get_color_palette(::ColorGradient, ::Any) at C:\Users\Max\.julia\packages\PlotUtils\es5pb\src\colorschemes.jl:326

Stacktrace:
 [1] top-level scope at In[49]:9
 [2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

```

---

<div class="post-metadata">

**Author:** ![dgleich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dgleich/32/1494_2.png) [@dgleich](https://discourse.julialang.org/u/dgleich)\
**Post date:** [June 29, 2021, 2:43pm UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/6 "2021-06-29T14:43:52Z")

</div>

Looks like the solution is now

```julia
theme_palette(:auto)

```

as in

```julia
cur_colors = theme_palette(:auto)
pp = range(0,1,length=50)

plot()
for (cur_index, cur_color) in enumerate(cur_colors[1:3])
    plot!(pp, 0 .+ pp .+ cur_index .- 7)
end
for (cur_index, cur_color) in enumerate(cur_colors[1:3])
    plot!(pp, 1 .- pp .+ cur_index .-7, color=cur_color)
end
plot!()
```

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [July 9, 2021, 6:37am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/7 "2021-07-09T06:37:43Z")

</div>

`theme_palette(:auto)` is working nicely.  
But how can I get the actual names of the colors?  
E.g. because I like this palette but want to assign selected colors to my plots.

---

<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:** [July 9, 2021, 8:52am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/8 "2021-07-09T08:52:14Z")

</div>

It seems odd that the default colors in `theme_palette(:default)` (same as `:auto`) are not defined in the [Colors.jl named colors list](https://github.com/JuliaGraphics/Colors.jl/blob/master/src/names_data.jl)?

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [July 12, 2021, 7:21am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/9 "2021-07-12T07:21:35Z")

</div>

Indeed they are not in the list.  
Extracting them is simple though (I am sure you already knew; posting this for reference).

```julia
mycolor = theme_palette(:auto).colors.colors[3]
plot([1,2],[1,2],color=mycolor)

```

---

<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:** [July 12, 2021, 7:31am UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/10 "2021-07-12T07:31:21Z")

</div>

> [@bernhard](#):
>
> `mycolor = theme_palette(:auto).colors.colors[3]`

It seems that one can write it more compactly:

```julia
mycolor3 = theme_palette(:auto)[3]
julia> mycolor == mycolor3
true

```

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [January 10, 2022, 12:11pm UTC](https://discourse.julialang.org/t/way-to-get-default-color-order-in-plots-jl/12643/11 "2022-01-10T12:11:59Z")

</div>

If one only wants to use the _i_-th color in the default palette (with no need of its name), then the simplest way is still `color=i`.

```julia
plot(;size=(400, 230))
for i = 1:5
    plot!(rand(10); color=i % 2 + 1, label="y$i")
end
savefig("default_color.png")
current()

```

![default_color](https://global.discourse-cdn.com/julialang/original/3X/6/2/6258cf1b484f0285780eca1d2db459cfebc5834a.png)
