GiovineItalia / Gadfly.jl

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

[help] Discrete color labels with continuous color scheme. Also a question about references in academic work. #437

Open joshjob42 opened 9 years ago

joshjob42 commented 9 years ago

I'm preparing a set of figures for a paper using Gadfly. I'm not sure if one is supposed to reference things like this (either Julia or particular packages like Gadfly). Do you happen to know?

In any case, the figures are all quite beautiful except for one issue. I have plots with multiple curves, each curve is a different color which corresponds to the value of some parameter. If I plot it with a continuous color scale, the plot is quite attractive to the eye as the curves form a sort of rainbow. However, I would very much like each curve to have it's own entry in the legend so that one can trivially compare and precisely pinpoint the value of the parameter corresponding to each curve. Scale.discrete_color's color choice is quite unattractive to me however.

Is there any way to change the colors used when you use Scale.discrete_color to be the same as in the continuous case?

dcjones commented 9 years ago

There is a Scale.discrete_color_manual that may help.

colors = linspace(convert(LCHuv, color("orange")),
                  convert(LCHuv, color("sky blue")), 8)

plot(x=rand(102), y=rand(100),
     color=[["A", "B", "C", "D", "E", "F"][i] for i in rand(1:6, 100)],
     Scale.discrete_color_manual(colors...),
     Geom.line)

try

If Julia plays a major role in you analysis, it would be good to cite it. There is a julia paper. You don't need to cite Gadfly, but it'd appreciated if you do. I'm going to get a DOI for the repository that will let you do that. See #438

dcjones commented 9 years ago

And that color scale was a silly example. If you want something like ggplot2's default:

colors = linspace(LCHuv(70, 70, 0), LCHuv(70, 70, 315), 8)

try

joshjob42 commented 9 years ago

Is there any way of finding what colors are used in the default continuous color scale? I.e. when I say "plot(df, x=:x, y=:y, color=:A)" can I find out what colors are actually used in the resulting plot?

dcjones commented 9 years ago

It's not necessarily something I had in mind, but you can do this:

colors = [Scale.continuous_color().f(p) for p in linspace(0, 1, 6)]

Scale.continuous_color().f(p) constructs a default continuous color scale and calls it's color generating function f, which takes a value in [0, 1] and returns a color. linspace(0, 1, 6) generates 6 such numbers. So just replace 6 with however many colors you actually need.

try

joshjob42 commented 9 years ago

I'm seeing colors that are significantly lighter in hue than the actual continuous plot.

screen shot 2014-09-29 at 9 44 32 am screen shot 2014-09-29 at 9 44 16 am

I followed your last post's strategy. The colors look right, they're just too light.

The odd thing is if I call "Scale.continuous_color()" instead of "Scale.discrete_color_manual(colors...)" I recover the darker colors, yet when I'm seemingly plotting the same colors using discrete labels they are lighter. Any idea for the cause (and a potential cure)?