It appears that you are using MeshFunctions -> {Abs[#2] &}
to cause the curve to change color when it crosses +1.5
and -1.5
, but it does not. This is because, although a line segment of data
may cross one of those values, the corresponding line segment of Abs[data]
does not necessarily do so. For clarity, consider data modified by two additional points at +3
and -3
, with the goal of causing the color to change at exactly +1.5
and -1.5
.
data = RandomReal[{-3, 3}, 100]; data = Append[data, 3]; data = Append[data, -3];
The plot in the Question (with PlotRange -> {-3, 3}
added for clarity) is
ListLinePlot[data, MeshFunctions -> {Abs[#2] &}, Mesh -> {1},
MeshShading -> {Red, Green}, MeshStyle -> None, PlotRange -> {-3, 3}]
The lines near 16
, for instance, do not change color. Next, plot Abs
of the same data
ListLinePlot[Abs[data], MeshFunctions -> {#2 &}, Mesh -> {1},
MeshShading -> {Red, Green}, MeshStyle -> None, PlotRange -> {-3, 3}]
We see that lines of Abs[data]
never cross +1.5
at 16
and so do not change color. Hence, they do not change color in the first plot eiher.
To assure the desired color change, the approach suggested by belisarius in his Comment seems preferable.
ListLinePlot[data, MeshFunctions -> {(#2) &}, Mesh -> {{1, -1}}, MeshShading -> {Red, Blue}, MeshStyle -> None]
$\endgroup$Subscript[m, i]
should normally be chosen to be continuous monotonic functions", whereSubscript[m, i]
represent the mesh functions.Abs
is not monotonic. $\endgroup$