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.

The following code

ListLinePlot[{2, 4, 6, 8, 10, 12}, 
 ColorFunction -> Function[{x, y}, If[x <= 3, Blue, Red]]]

should produce blue lines for $x\le3$ and red lines for $x\ge3$. But instead, the plot contains only blue lines.

Where are my red lines?

share|improve this question
2  
ColorFunctionScaling –  Brett Champion Jun 18 '12 at 18:05
    
Why should I use ColorFunctionScaling? My specific color function delivers Blue or Red – two well defined color directives. –  Deniz Jun 18 '12 at 18:08
1  
@Deniz B/c ColorFunctionScaling prevents the scaling of the argument, not of the function –  belisarius Jun 18 '12 at 18:50

2 Answers 2

up vote 8 down vote accepted

Try

ListLinePlot[{2, 4, 6, 8, 10, 12}, 
ColorFunction -> Function[{x, y}, If[x <= 3, Blue, Red]], 
ColorFunctionScaling -> False, PlotStyle -> Thick, Mesh -> All, 
MeshStyle -> {Orange, PointSize[0.03]}, PlotRange -> 13, 
Frame -> True]

enter image description here

share|improve this answer
1  
Mesh is a substitute for PlotMarkers? Didn't know that! –  Verbeia Jun 18 '12 at 20:25

Here's how to drive Brett's and belisarius's point home. Let's modify your original code a bit so we can see exactly what things are passed to your ColorFunction:

Reap[ListLinePlot[{2, 4, 6, 8, 10, 12},
     ColorFunction -> Function[{x, y}, Sow[x]; If[x <= 3, Blue, Red]]]]

We obtain your erroneous plot as the first component of a list, and the list of all the values passed to your ColorFunction: {{0., 0.2, 0.4, 0.6, 0.8, 1.}} as the second component. Effectively, what was done is to apply Rescale[] to the original list you plotted (i.e. Rescale[N@{2, 4, 6, 8, 10, 12}]). That's because ColorFunctionScaling is by default set to True:

Options[ListLinePlot, ColorFunctionScaling]
{ColorFunctionScaling -> True}

Let's see what happens if we disable ColorFunctionScaling:

ListLinePlot[{2, 4, 6, 8, 10, 12}, 
 ColorFunction -> Function[{x, y}, If[x <= 3, Blue, Red]], 
 ColorFunctionScaling -> False]

doubly-colored ListLinePlot

Note the nice purplish shade in between 3 and 4, showing that the color interpolation is working nicely.

share|improve this answer

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.