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.

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?

share|improve this question
    
It this a duplicate? How to blend colors on a curve? –  Kuba Aug 27 '13 at 10:45
    
Also related –  Kuba Aug 27 '13 at 10:53
    
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. –  matt525252 Aug 27 '13 at 10:56
    
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. –  matt525252 Aug 27 '13 at 11:10
1  
Graphics[{Thick, Line[data, VertexColors -> Array[Blend["Rainbow", #/Length@data] &, Length@data]] }] –  Kuba Aug 27 '13 at 11:13

1 Answer 1

up vote 2 down vote accepted

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]]}]
share|improve this answer
    
@user9248 Please, hold on with an accept. This may discourage others :) –  Kuba Aug 27 '13 at 11:49

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.