GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 250 forks source link

Find out what the default Gadfly color values are #602

Open woest opened 9 years ago

woest commented 9 years ago

I know I can introduce colors manually, but I like the color scheme of Gadfly, and could not find an easy way to retrieve a vector of colors in the default order as used by Gadfly.

Did I miss something? I could not find anything in the documentation, and the closest I got (but did not know what to do with it) by browsing through the code is Gadfly.Scale.color_discrete

dcjones commented 9 years ago

The color palette is generated, so you won't find all the colors listed explicitly anywhere. But you can generate them yourself. Here's the code Gadfly uses:

using Color

n = 12
distinguishable_colors(n, ColorValue[LCHab(70, 60, 240)],
                       transform=c -> deuteranopic(c, 0.5),
                       lchoices=Float64[65, 70, 75, 80],
                       cchoices=Float64[0, 50, 60, 70],
                       hchoices=linspace(0, 330, 24))

You can change n to get the desired number of colors (which can be arbitrarily large).

woest commented 9 years ago

Nice :). Thanks a lot for that.

Possibly a nice addition for the documentation?

Or even add a wrapper function around it so people can call it with always the same lchoices/cchoices/hchoices Gadfly uses (if those settings ever change in the future).

woest commented 9 years ago

Nevermind, I should have known how to do this:

julia> using Gadfly

julia> a = Scale.color_discrete_hue()
DiscreteColorScale((anonymous function),nothing,nothing,true)

julia> a.f(3)
3-element Array{ColorValue{T},1}:
 LCHab{Float64}(70.0,60.0,240.0)             
 LCHab{Float64}(80.0,70.0,100.43478260869566)
 LCHab{Float64}(65.0,70.0,0.0)    
GordStephen commented 9 years ago

@woest Great tip, thanks!