1
$\begingroup$

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?

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

1 Answer 1

5
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Clever solution! Thanks! $\endgroup$ Commented Jun 17, 2013 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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