# How to iteratively change RGB style in Show[Table[ListPlot[…]]] and create a Legend?

I am trying to plot the outputs of a ListPlot with different colors for the 3 different cases and create a legend. I have tried with a simple For cycle, but then got that obviously that is not working because Mathematica correctly recognizes what is inside ListPlot as UNIQUE function, therefore my cycle is ineffective. How else can I do to obtain three different colors?

 fExact = Table[Table[Table[j i^2, {i, 10^k, 10^(k + 1), If[k >= 1, 10^k,10^(k
- 1)]}],{k, 0, 1, 1}], {j, {1, 2, 3}}];
vector = Table[Table[Table[i, {i, 10^k, 10^(k + 1), If[k >= 1, 10^k, 10^(k
-1)]}],{k, 0, 1, 1}], {j, {1, 2, 3}}];
Show[Table[Table[ListPlot[Transpose[{Transpose[{vector[[j]], fExact[[j]]}][[k]][],
Transpose[{vector[[j]], fExact[[j]]}][[k]][]}], PlotStyle -> For[j = 1, j <= 3, j++,
RGBColor[j, 0, 1]],
Joined -> True], {k, 1, 1, 1}], {j, 1, 3, 1}],
PlotRange -> {{0.001, 10}, {0.01, 10}}]


If I call:

try = Table[Table[ListPlot[Transpose[{Transpose[{vector[[j]], fExact[[j]]}][[k]][],
Transpose[{vector[[j]], fExact[[j]]}][[k]][]}], Joined -> True,
PlotStyle -> For[j = 0, j < 3, j++, RGBColor[j, 0, 1]]], {k, 1, 1,1}], {j, 1, 3, 1}]


I get: Is there any way to access the PlotStyle option of the random try[[j]] element of try? In that way it should be easy to make a cycle and get what I want.

As for the legend, I tried PlotLegends->{j} but didn't work.

• You can do PlotStyle->RGBColor[j,0,1]? (This isn't going to look very nice BTW.) I'd do something like PlotStyle->ColorData[j]. – N.J.Evans Apr 27 '17 at 13:54
• @N.J.Evans why not nice? anyway, I 've just done what you suggested and still get that ALL the curves have the same colour following the first suggestion that you gave. Instead, the second one works! – Andrea G Apr 27 '17 at 13:58
• rule number one for use of For is don't ever use it for anything (ever). If you insist on using it, realize It doesn't return anything. In this case its really unclear what you even intend by by using the outside Table iterator as a loop variable inside a For loop. – george2079 Apr 27 '17 at 14:09
• RGBColor needs three arguments. Other things you can do for simple cases is like this {Red, Green, Blue}[[j]] , or Hue[j/4] . – george2079 Apr 27 '17 at 14:47
• RGBColor arguments need to be in range 0-1 so RGBColor[j/4, 0, 1] may work (Although the colors will all be shades of purple so may not look very different ). – george2079 Apr 27 '17 at 15:30