# Is it possible to style multiple Plot or ListPlot curves using a color gradient?

I am using Mathematica 8. In Mathematica, there is a default PlotStyle coloring in Plot and ListPlot. For example, suppose I have a series of nine functions stored in the list functions. Mathematica styles the different curves in a cyclic way (I think that the default is cycles of "blue", purple, dark yellow, green), as in this example:

functions = Table[a*Cos[x], {a, 0.2, 1, 0.1}]
Plot[functions, {x, 0, 2 Pi}]

{0.2 Cos[x], 0.3 Cos[x], 0.4 Cos[x], 0.5 Cos[x], 0.6 Cos[x], 0.7 Cos[x], 0.8 Cos[x],
0.9 Cos[x], 1. Cos[x]}


This is nice, but now suppose that I want to color the multiple curves using some sort of gradient (perhaps one of the gradients in ColorData). Is this possible in Plot and ListPlot?

I could do this somewhat manually. For example, if I wanted a blue gradient, I could write the following (although this choice of colors could somehow be improved):

Plot[functions, {x, 0, 2 Pi}, PlotStyle -> {
Lighter[Lighter[Lighter[Lighter[Blue]]]],
Lighter[Lighter[Lighter[Blue]]],
Lighter[Lighter[Blue]],
Lighter[Blue],
Blue,
Darker[Blue],
Darker[Darker[Blue]],
Darker[Darker[Darker[Blue]]],
Darker[Darker[Darker[Darker[Blue]]]]
}]


However, this becomes complicated if I have many curves or if I want to use a more complex gradient such as rainbow (e.g., ColorData["Rainbow"]), temperature map (e.g., ColorData["TemperatureMap"]), etc. Do you have any suggestions?

-
Is this ok or You want more automatic option? Plot[Evaluate@Table[Sin[x] + t, {t, 0, 1, .1}], {x, 0, Pi}, PlotStyle -> Table[Blend[{White, Blue, Black}, i], {i, 0, 1, .1}]] Blend works also with palletes. Blend["Rainbow",x] – Kuba Jun 27 '13 at 20:47
@Kuba This is nice! Thank you! I just need to scale with respect to the number of curves, perhaps using Table[i/Length[functions], {i, 1, Length[functions]}], as halirutan does below. – Andrew Jun 27 '13 at 20:56

One pretty easy thing is to create a table of the gradient colors directly inside the Plot. The only thing you need to take care of is the scaling. All the color gradients take values between [0,1] when you access ColorData["GradientName",x]. Therefore, you need to now the number of your functions:

functions = Table[a*Cos[x], {a, 0.2, 1, 0.1}]
Plot[functions, {x, 0, 2 Pi},
PlotStyle ->
Table[ColorData["Rainbow", i/(Length[functions]-1)], {i,0, Length[functions]-1}]
]


If you want a sneak preview for all color schemes, you can quickly hack some Manipulate

With[{
control = (ColorData[#, "ColorFunction"] ->
Show[ColorData[#, "Image"], ImageSize -> 90]) & /@ ColorData["Gradients"],
fns = Table[a*Cos[x], {a, 0.2, 1, 0.1}]},
Manipulate[
Plot[fns, {x, 0, 2 Pi},
PlotStyle ->
Table[s@Rescale[c, {1, Length[fns]}, {cmin, cmax}], {c,
Length[fns]}]],
{{s, control[[1, 1]], "Color Scheme"}, control},
{{cmin, 0, "Color Min"}, 0, cmax},
{{cmax, 1, "Color Max"}, .1, 1}
]
]

-
Thanks! This is just a thought... instead of using Table[ColorData["Rainbow", i/Length[functions]], {i, Length[functions]}], another possibility might be Table[ColorData["Rainbow", i], {i, 0, 1, 1/(Length[functions] - 1)}]. Whereas Table[i/Length[functions], {i, Length[functions]}] gives {1/9, 2/9, 1/3, 4/9, 5/9, 2/3, 7/9, 8/9, 1}, Table[i, {i, 0, 1, 1/(Length[functions] - 1)}] gives {0, 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, 1}. Thank you so much for your time and detailed and excellent help! – Andrew Jun 27 '13 at 21:15
@Andrew Hehe, yes you are right. I was about to edit the answer shortly, but I'm preparing something else I want to include ;-) – halirutan Jun 27 '13 at 21:17
Thank you so very much! :-) – Andrew Jun 27 '13 at 21:22