Message Boards Message Boards


How to color a ListLinePlot plot with derivative values?

Posted 10 years ago
3 Replies
3 Total Likes
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 is
I would like to color the lines between the mesh points using the "derivative" array
generated in the following way:
This process of coloring can be summarized in order to plot the entire array in one drawing?

POSTED BY: jose muñoz
3 Replies
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 color
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 BY: Vitaliy Kaurov
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};
(* {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 BY: Nasser M. Abbasi
Posted 10 years ago
yes, i have made a mistake in the example, but the original question remains unanswered.
POSTED BY: jose muñoz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract