1
|
5825 Views
|
3 Replies
|
3 Total Likes
View groups...
Share

# How to color a ListLinePlot plot with derivative values?

Posted 10 years ago
 I have an array of dimensions {n,M}, and for every nth curve generated, I want to color it using the "discrete" derivative information, that is to say, by using the slope of this linear-piecewise curve. For example, if the nth curve isncurve={1,2,3,3,2,4,2,1}I would like to color the lines between the mesh points using the "derivative" array de={1,1,0,0,-1,2,-2,-1}generated in the following way:For[i=1,i<=7,i++,de[[i]]=ncurve[[i+1]]-ncurve[[i]]];[/i][/i]This process of coloring can be summarized in order to plot the entire array in one drawing?Thanks
3 Replies
Sort By:
Posted 10 years ago
 Please notice how Mathematica code is formatted on this site and follow this formatting.About your question. I am not sure why are you complicating things - first let's figure out how to do it for a single data set. Then you can generalize for all curves. Define a function:f[data_] := {Thickness[.01], Opacity[.9], CapForm["Round"], ColorData["Rainbow"][#2], Line[#1]} & @@@   Transpose[{Partition[data, 2, 1], Rescale[Differences[data[[All, 2]]]]}]Now visualize. Note I am adding noise to show the effect changing of slope has on colorManipulate[ SeedRandom; data = Table[{x, 2 Sin[x] + RandomReal[h]}, {x, 0, 4 Pi, .1}]; Graphics[f[data], Frame -> True, ImageSize -> 800, AspectRatio -> 1/4] , {h, 0, 1}] Posted 10 years ago
 If you show more data (ncurves) that will help with some MWE.  But for your derivatives, what you show does not look correct. Mathematica has a function for this that you should be using:ncurve = {1, 2, 3, 3, 2, 4, 2, 1};Differences[ncurve](* {1, 1, 0, -1, 2, -2, -1} *)The above is different from what you have in your question. One should get a differences list with length that is one less than the original list.
Posted 10 years ago
 yes, i have made a mistake in the example, but the original question remains unanswered.