-3

This is what I want.

I want to change the colors as I progress through a list. enter image description here

Gappy Hilmore
  • 1,253
  • 1
  • 9
  • 17

2 Answers2

4

For illustrative purposes:

f[t_] := {Sqrt[2] Cos[t], Sqrt[2] Cos[t] Sin[t]}/(1 + Sin[t]^2)
r = Range[0, 2 Pi, 0.05];
cf = ColorData["Rainbow"][1 - #/(2 Pi)] &;
lp = ListPlot[{f@#} & /@ r, PlotStyle -> (cf /@ r), 
   AspectRatio -> Automatic, ImageSize -> 400];
g = Graphics[{cf@#, PointSize[0.01], Point[f@#]} & /@ r, 
   ImageSize -> 400];
pp = ParametricPlot[f[t], {t, 0, 2 Pi}, 
   ColorFunction -> (cf[2 Pi #3] &), PlotStyle -> Thickness[0.01], 
   ImageSize -> 400];
Grid[Transpose[{{"ListPlot", "Graphics", "ParametricPlot"}, {lp, g, 
    pp}}]]

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
3

I have always felt that Mathematica's ListPlot needed this feature. It is possible that a feature like this has been added in version 10.1, but prior to that, the best I know of is to use Graphics directly, which isn't nearly as hard as it sounds:

points = Table[{x^4, Sin[x^4]}, {x, 0, (2*Pi)^(1/4), 0.01}];
colors = Map[Hue[2/3*(#[[1]]/(2*Pi))] &, points];
Graphics[Thread[{colors, Point /@ points}]]

First attempt

This is pretty close; if you want to make it look more like the ListPlot, you'll want to add axes and maybe change the aspect ratio:

Graphics[
  Thread[{colors, Point /@ points}],
  AspectRatio -> 1/GoldenRatio,
  Axes -> True]

Second attempt

nben
  • 2,148
  • 9
  • 20
  • Does using ColorFunction with ListPlot, allow you to apply a custom list of colors to the plot points? Last I remember looking into it, you would have to look them up in a table or something to figure out how to match the colors to the points. – nben May 09 '15 at 00:50
  • The question isn't very specific, but the example plot clearly doesn't vary with x or y in a trivial way, which is all the docs seem to imply that you can do with ColorFunction. – nben May 09 '15 at 01:03