3
$\begingroup$

I have the following data

data = {{0, 0}, {-0.0385, 0.0667}, {-0.0566, 0.1283}, {0.0966, 
    0.0441}, {-0.1166, 
    0.0038}, {-0.2046, -0.0673}, {-0.2536, -0.21}, {-0.5485, \
-0.2643}, {-0.3702, -0.1148}, {-0.4201, -0.2319}, {-0.5558, -0.2748}, \
{-0.693, -0.3272}, {-0.6276, -0.3844}, {-0.6305, -0.3448}, {-0.671, \
-0.4833}, {-0.6809, -0.3441}, {-0.7082, -0.2548}, {-0.5978, -0.3126}, \
{-0.4337, -0.3588}, {-0.2542, -0.4139}, {-0.3318, -0.3318}, {-0.4991, \
-0.2123}, {-0.4195, -0.1966}, {-0.4797, 0.0285}, {-0.2198, 
    0.0965}, {-0.1914, 0.1604}, {-0.0854, 0.1668}, {0.0715, 
    0.3025}, {0.0847, 0.3116}, {0.175, 0.3152}, {0.0123, 
    0.4577}, {0.0941, 0.4445}, {0.083, 0.3729}, {0.1251, 
    0.1414}, {0.0239, 0.3119}, {-0.0665, 0.3748}, {-0.0171, 
    0.4261}, {0.0781, 0.4031}, {-0.0945, 0.315}, {-0.2497, 
    0.3892}, {-0.285, 0.3823}, {-0.2873, 0.4343}, {-0.196, 
    0.4628}, {-0.2812, 0.5166}, {-0.186, 0.2917}, {-0.3101, 
    0.3047}, {-0.4103, 0.2439}, {-0.4335, 0.2251}, {-0.5113, 
    0.4149}, {-0.6487, 0.4662}, {-0.5045, 0.1807}};

which represents movement of some particle in time 0,...,50.

Using ColorFunction is possible to get rainbow color according to axis $y$ as

ListLinePlot[data,ColorFunction->Function[{x,y},ColorData["Rainbow"][y]],PlotStyle->Thick]

or axis $x$ as

ListLinePlot[data,ColorFunction->Function[{x,y},ColorData["Rainbow"][x]],PlotStyle->Thick]

Is it possible to use ColorFunction according to time 0,...,50 and to get rainbow according to its movement in this time?

$\endgroup$
6
  • $\begingroup$ It this a duplicate? How to blend colors on a curve? $\endgroup$
    – Kuba
    Commented Aug 27, 2013 at 10:45
  • $\begingroup$ Also related $\endgroup$
    – Kuba
    Commented Aug 27, 2013 at 10:53
  • $\begingroup$ Time example I posted (0,...,50) just means that there is 51 steps in order {0,0},....,{-0.5045,0.1807} from data.I would like to redistribute the rainbow color according to the order of the points (which could be understood as a time). Not just by individual axes. $\endgroup$
    – matt525252
    Commented Aug 27, 2013 at 10:56
  • $\begingroup$ colloring according to axis y would be: img266.imageshack.us/img266/8488/5gc.png and according to x: img716.imageshack.us/img716/7307/xpt.png But what I need is according to order of points. It means the first point is purple/blue and rainbow continue on following points and red colour is at last points. $\endgroup$
    – matt525252
    Commented Aug 27, 2013 at 11:10
  • 1
    $\begingroup$ Graphics[{Thick, Line[data, VertexColors -> Array[Blend["Rainbow", #/Length@data] &, Length@data]] }] $\endgroup$
    – Kuba
    Commented Aug 27, 2013 at 11:13

1 Answer 1

3
$\begingroup$

It seems that the links that I've provided are closely related but not duplicates. I decided to write this answer but I will add an extension which may be useful for others.

This is what OP finds well suited to his needs:

Graphics[{Thick, 
         Line[data, 
              VertexColors -> Array[Blend["Rainbow", #/Length@data] &, Length@data]]}]

However one may want to blend the palette along the lines but scalled with path not with number of vertex as in the former example.

path = {0} ~ Join ~ Accumulate[EuclideanDistance @@@ Partition[data, 2, 1]];

Graphics[{Thick, 
     Line[data, 
     VertexColors -> Array[Blend["Rainbow", path[[#]]/Last@path] &, Length@data]]}]
$\endgroup$
0

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.