Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Say i have this data:

data1 = Map[Cos, Range[0, 20]];
data2 = Map[Sin, Range[0, 20]];

And i want to plot data1 in gray and a chosen set (with Manipulate) of multiplicities of data2 in several other colors. This code does what I mean:

Manipulate[
 ListLinePlot[{data1, Sequence @@ Table[data2*i, {i, k}]}, 
  PlotStyle -> {LightGray, 
    Sequence @@ ConstantArray[Automatic, Length[k]]}], {{k, {1, 
    2}}, {1, 2, 3, 4}, ControlType -> CheckboxBar}]

I managed to make it work to only plot data1 in gray and the multiplicities of data2 in automatic colors, but now I'm stuck at the standard color scheme, although PlotStyle accepts ColorData. For example:

PlotStyle -> ColorData[3, "ColorList"]

However I don't know how to implement this with the condition that the first plot should be gray.

Question: Is there a way to change the color scheme in ListPlot AND manually choose the color of the first plot?

share|improve this question
    
It is because of iterator, it seems to work: PlotStyle -> {Gray, Sequence @@ Table[Hue[i/10], {i, k }]} –  Kuba Jun 17 '13 at 12:41
    
I think I don't fully understand what you mean. Could you explain it a little more? –  A. Goossens Jun 17 '13 at 18:26
    
Maybe I missed the point but I thought You have problem with creating list for PlotStyle, with dynamic length, starting from Gray. –  Kuba Jun 17 '13 at 18:30
    
Then I probably haven't made myself clear enough... Rold Lm's solution was exactly what I was looking for. –  A. Goossens Jun 18 '13 at 6:07
add comment

1 Answer

up vote 3 down vote accepted

You can try this:

data1 = Map[Cos, Range[0, 20]];
data2 = Map[Sin, Range[0, 20]];    
Manipulate[
  G1 = ListLinePlot[data1, PlotStyle -> {Thick, c0}, 
    PlotRange -> {-4, 4}];
  G2 = ListLinePlot[Table[data2*i, {i, k}], PlotStyle -> Thick, 
    ColorFunction -> Function[{x1, x2}, ColorData[c1][x2]]];
  Show[G2, G1],
  {{k, {1, 2, 3, 4}}, {1, 2, 3, 4}, ControlType -> CheckboxBar},
  {c0, Gray, ColorSlider},
  {c1, ColorData["Gradients"], PopupMenu}]

Result:

enter image description here

You can also try this if you want to manually choose every color:

data1 = Map[Cos, Range[0, 20]];
data2 = Map[Sin, Range[0, 20]];
Manipulate[
  ListLinePlot[{data1, Sequence @@ Table[data2*i, {i, k}]}, 
    PlotStyle -> {{c0, Sequence @@ ConstantArray[Automatic, Length[k]]}, c1, c2, c3, c4}], 
  {{k, {1, 2}}, {1, 2, 3, 4}, ControlType -> CheckboxBar},
  {c0, Gray, ColorSlider},
  {c1, Red, ColorSlider},
  {c2, Green, ColorSlider},
  {c3, Blue, ColorSlider},
  {c4, Yellow, ColorSlider}]

Result:

enter image description here

share|improve this answer
    
Clever solution! Thanks! –  A. Goossens Jun 17 '13 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.