# Colors in ListPlot

I have to generate 10-50 random real numbers,.. List[ RandomReal[{-10, 10}, {RandomInteger [{10, 10}]}]] This I've done, but I also have to make a ListPlot in which numbers from 10 to 1 will be blue, from 0,99 to -0,99 will be red and from -1 to 10 will be green. I tried to separate the list to 3 lists, I also tried to use conditions but I can't make it work,.. Could someone help?

• Have you seen Select[]? Nov 8, 2017 at 11:45
• There should be a solution that uses ColorFunction but I see nothing in the Help. Anyone?
– A.G.
Nov 8, 2017 at 14:09
• @A.G. - For ListPlot, "ColorFunction requires at least one dataset to be Joined", i.e., it will vary the color of a line not points. Nov 8, 2017 at 14:21

Generate 50 random pairs of data

SeedRandom;
data = RandomReal[{-10, 10}, {50, 2}];


SortBy the Last element of each pair and then split into the three groups using SplitBy the Last element

data3 = SplitBy[SortBy[data, Last], Abs[Last@#] > 1 &];


ListPlot the three groups of data

ListPlot[data3, PlotStyle -> {Green, Red, Blue}] • This breaks with SeedRandom. Nov 8, 2017 at 13:09
• @ChrisDegnen - For RandomSeed there is no data in the range -1 < y < 1 so there is no split thereby resulting in a single color. Nov 8, 2017 at 14:25
• Exactly. Everything from -10 to +10 is coloured green, whereas the positive data points should be blue. Nov 8, 2017 at 14:29
rand = RandomReal[{-10, 10}, RandomInteger[{10, 50}]];
bluelist = redlist = greenlist = {};
Which[1 <= # <= 10, AppendTo[bluelist, #],
-1 <  # <   1, AppendTo[redlist, #],
-10 <= # <= -1, AppendTo[greenlist, #]] & /@ rand;
ListPlot[#1, PlotStyle -> #2] & @@
Transpose[DeleteCases[
{{bluelist, Blue}, {redlist, Red}, {greenlist, Green}}, {{}, _}]] Does this help?:

SeedRandom[10, Method -> "MKL"];
data = Transpose[{RandomReal[{-10, 10}, 50],RandomInteger[{-10, 10}, 50]}];
colors = Piecewise[{{RGBColor[1, 0, 0], 1 <= #[] <= 10},
{RGBColor[0, 1, 0], -0.99 <= #[] <= 0.99},
{RGBColor[0, 0, 1], -10 <= #[] <= -1}}] & /@ data;
Graphics[{PointSize[0.02], Point[data, VertexColors -> colors]},
AspectRatio -> 1, Frame -> True] 