Default linecolor name in Plots.jl?

Hello. I thought that the default linecolor for plotting lines in Plots.jl was :steelblue. But upon close examination, it seems to be different. It’s actually closer to :dodgerblue. Is there any julia function that returns the linecolor name just used?
Thanks a lot!

1 Like

I think you can get the palette using PlotThemes.theme_palette(:default). It gives me this

ColorPalette(ColorSchemes.ColorScheme{Vector{RGB{Float64}}, String, String}(RGB{Float64}[RGB(0.0, 0.6056031704619725, 0.9786801190138923), RGB(0.8888735440600661, 0.435649148506399, 0.2781230452972766), RGB(0.24222393333911896, 0.6432750821113586, 0.304448664188385), RGB(0.7644400000572205, 0.4441118538379669, 0.8242975473403931), RGB(0.6755439043045044, 0.5556622743606567, 0.09423444420099258), RGB(0.0, 0.6657590270042419, 0.6809969544410706), RGB(0.9307674765586853, 0.3674771189689636, 0.5757699012756348), RGB(0.776981770992279, 0.5097429752349854, 0.14642538130283356), RGB(5.29969987894674e-8, 0.6642677187919617, 0.5529508590698242), RGB(0.558464765548706, 0.59348464012146, 0.11748137325048447), RGB(0.0, 0.6608786582946777, 0.7981787919998169), RGB(0.609670877456665, 0.49918484687805176, 0.9117812514305115), RGB(0.38000133633613586, 0.5510532855987549, 0.9665056467056274), RGB(0.9421815872192383, 0.3751642107963562, 0.4518167972564697), RGB(0.8684020638465881, 0.39598923921585083, 0.7135148048400879), RGB(0.4231467843055725, 0.6224954128265381, 0.19877080619335175)], "", ""))

And I’m pretty sure the default blue is RGB(0.0, 0.6056031704619725, 0.9786801190138923). Not sure if it has a name. I’ll dig around and update


Update: I’ve found the default colors here: PlotUtils.jl/src/color_utils.jl at e1beb9e3346fb60ed8753d34839b9c8f72adc5a7 · JuliaPlots/PlotUtils.jl · GitHub

function generate_colorscheme(
    bgcolor = plot_color(:white);
    color_bases = plot_color([colorant"steelblue", colorant"orangered"]),
    lightness = lightness_from_background(bgcolor),
    chroma = _lch_c_const[],
    n = 17,
)
    seed_colors = vcat(bgcolor, map(c -> adjust_lch(c, lightness, chroma), color_bases))
    seed_colors = convert(Vector{RGB{Float64}}, seed_colors)
    colors = distinguishable_colors(
        n,
        seed_colors,
        lchoices = Float64[lightness],
        cchoices = Float64[chroma],
        hchoices = range(0; stop = 340, length = 20),
    )[2:end]
    ColorScheme(colors)
end

So it is colorant"steelblue", and seems like it’s ran through adjust_lch which I think is converting the color to LCHab color space, taking the hue, constructing an LCHab instance with given lightness and colorfulness, and then converting back to RGBA. Why? idk I have no idea how colors work, I just did “go to definition” in my editor. Maybe the difference you’re seeing is because of this, but the colorant is steel blue.

adjust_lch(color, l, c) = convert(RGBA{Float64}, LCHab(l, c, convert(LCHab, color).h))

Update 2: Yes there is a difference between the default blue and steel blue. It’s there because of that function above. I ran it with the default values of l and c and got this.

julia> cp = theme_palette(:default);

julia> convert(RGB, PlotUtils.adjust_lch(colorant"steelblue", PlotUtils.lightness_from_background(plot_color(:white)), PlotUtils._lch_c_const[]))
RGB{Float64}(0.0, 0.6056031549975471, 0.9786801270072305)

julia> cp.colors.colors[1]
RGB{Float64}(0.0, 0.6056031704619725, 0.9786801190138923)

julia> colorant"steelblue"
RGB{N0f8}(0.275, 0.51, 0.706)

Thank you very much for your investigation!!
But then, how can we specify the exact color of colorant"steelblue" in the plot function explicitly via color= argument? If we specify it by color=:steelblue or color=colorant"steelblue", it renders a bit different color than the original default linecolor. Sometimes, we want to specify that color explicitly.

You can get the default blue by getting the first color in the color palette

using Plots

default_blue = theme_palette(:default)[1]
1 Like

Thanks a lot, @cocoa1231 !! It worked! However, it would be really great if there is a standard name for it, like :steelblue or :dodgerblue, etc. I hope someone who knows the colorscheme can help us.

FWIW, I get the deepskyblue2 as the “closest” color by running:

using Plots, Colors, LinearAlgebra

default_blue = theme_palette(:default)[1]
c0 = [default_blue.r, default_blue.g, default_blue.b]

name = ""
d = 1.0
for c in Colors.color_names
    dc = norm([(c.second ./255)...] - c0)
    if dc < d
        name = c.first
        d = dc
    end
end
println(name)           # deepskyblue2

Thanks a lot, @rafael.guerra! However, by running the following MWE, :dodgerblue seems to be closer to the default blue:

using Plots
default_blue = theme_palette(:default)[1]
x=collect(1:10)
plot(x, x, linewidth=10, label="default blue")
plot!(x, x.+1, linewidth=10, color=default_blue, label="from palette")
plot!(x, x.+2, linewidth=10, color=:deepskyblue2, label=":deepskyblue2")
plot!(x, x.+3, linewidth=10, color=:dodgerblue, label=":dodgerblue")
plot!(x, x.+4, linewidth=10, color=:steelblue, label=":steelblue")

Ok, the metric used was not good then.

By using a proper metric available in colordiff, we now get :dodgerblue1 as the closest color :

using Plots, Colors

c0 = first(theme_palette(:default))
name = ""
d = 100
for c in Colors.color_names
    dc = colordiff(RGB((c.second ./255)...), c0)
    if dc < d
        name = c.first
        d = dc
    end
end
println(name)           # dodgerblue1

Thanks a lot, @rafael.guerra and @cocoa1231 !!
Now, we have two choices:
(1) default_blue = theme_palette(:default)[1]; plot(..., color=default_blue) for exactly the same color as the default; or
(2) plot(..., color=:dodgerblue) for approximately the same color as the default one.
According to Colors.jl/src/names_data.jl at master · JuliaGraphics/Colors.jl, dodgerblue and dodgerblue1 are the same.