In a previous post, we saw how to change the colors in different segments of the ListPLot
when the intervals on the $x$ axis are given.
My question now is the following:
For the same test data how to change the color of the line in different segments according to the value of $y$. For example:
data = {{-3, -1}, {-2, -1}, {-1, -1}, {-0.2, -0.2}, {0, 0}, {0.5, 0.5},
{2, 2}, {3, 2}, {4, 2}};
- for $-0.92 < y < -0.5$ ---> red thick
- for $0.12 < y < 0.94$ ---> blue thick
- for $1.32 < y < 1.45$ ---> green thick
- in all other cases ---> black thick
IMPORTANT NOTE: The real data contain thousands of pairs which cannot be separated into sections. Only the intervals on the y axis are known. So, I want a continuous line with different colors in each segment.
What would be an elegant and quick way to do this?
MeshFunctions -> {#2 &}
and make the necessary adjustments in theMesh
setting. $\endgroup$