0
$\begingroup$

I'm finding strange behavior with ColorFunction. Say I want to color a plot to indicate the sign of abscissa (this is a simplification of a more complex plot I'd like to do):

Plot[
 Log[Abs[x]],
 {x, -2, 2},
 ColorFunction -> Function[{x, y}, Hue[\[Piecewise] {
      {0.7, x > 0},
      {0.0, x <= 0}
     }]]
 ]

It doesn't color the negative branch red as I would like, although if you look closely it colors the very first point red: enter image description here

It also doesn't work for the second argument either, and I don't understand the behavior:

Plot[
 Floor[x],
 {x, -2, 2},
 ColorFunction -> Function[{x, y}, Hue[\[Piecewise] {
      {0.7, y > 0},
      {0.0, y < 0}
     }]]
 ]

enter image description here

Changing only the domain, to plot from -5 to 5: enter image description here

$\endgroup$
1
  • 5
    $\begingroup$ In the ColorFunction option, the variables x and y are each scaled to the interval {0, 1}. To use the actual values, include the option ColorFunctionScaling -> False $\endgroup$
    – Bob Hanlon
    Mar 17 at 0:12

0

Browse other questions tagged or ask your own question.