Skip to main content

color - Time ColorFunction


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?



Answer



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]]}]

Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...

list manipulation - Selecting multiple columns from a matrix?

Sample data: data = { {{2013, 1, 1}, 24.13, 167.67, 231.82}, {{2013, 1, 2}, 32.15, 170.92, 225.99}, {{2013, 1, 3}, 35.43, 172.68, 221.67}, {{2013, 1, 4}, 36.73, 173.05, 218.32}, {{2013, 1, 5}, 58.19, 165.96, 197.05}, {{2013, 1, 6}, 69.99, 163.50, 187.52}, {{2013, 1, 7}, 71.37, 154.21, 175.58}, {{2013, 1, 8}, 72.51, 149.66, 163.25}}; I want a DateListPlot with three graphs, so for a matrix formed by columns 1 and 2, one for columns 1 and 3, and 1 for columns 1 and 4. At the moment I'm using this code: data2 = Transpose[{data[[All, 1]], data[[All, 2]]}]; data3 = Transpose[{data[[All, 1]], data[[All, 3]]}]; data4 = Transpose[{data[[All, 1]], data[[All, 4]]}]; DateListPlot[{data2, data3, data4}, Joined -> True, Filling -> {3 -> {1}}] but I have a hunch that this can be done more efficiently. I don't like the Transpose s in particular. Any ideas? edit (for extra credit) What if I need to multiply the second column by 2, which in my solution is simp...