Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.1K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to control the color of line segments in ListLinePlot?

POSTED BY: Tsai Ming-Chou
2 Replies

Assuming you only have discrete data and no access tot the function that generates the data,

colF = Interpolation[data[[All, {1, 3}]]];
ListLinePlot[data[[All, {1, 2}]], 
 ColorFunction -> Function[{x}, If[colF[x] <= 0, Red, Blue]], 
 ColorFunctionScaling -> False]

with the function available i would use Plot instead

Plot[Sin[x], {x, 0, 10}, 
 ColorFunction -> Function[{x}, If[Cos[x] <= 0, Red, Blue]], 
 ColorFunctionScaling -> False]
POSTED BY: Martijn Froeling

Thank you very much!
You provided me with such a good idea~~
Completely meets my needs.

data = Table[{x, Sin[x], Cos[x]}, {x, 0, 10, 0.1}];
colF = Interpolation[data[[All, {1, 3}]]];
ListLinePlot[data[[All, {1, 2}]], 
 ColorFunction -> Function[{x, y}, If[colF[x] <= 0.1, Red, Blue]], 
 ColorFunctionScaling -> False]

enter image description here

POSTED BY: Tsai Ming-Chou
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard