# How to plot points in a color corresponding to some value?

I want to attach one of two values (1 or -1) to some coordinates in the plane and plot these points in a color corresponding to this value, e.g. 1 shall correspond to Blue and -1 to Red. My coordinates and values are structured like this:

position = Table[{i, j}, {i, 0, 1}, {j, 0, 1}]
value = {{-1, -1}, {1, -1}}


In this example the coordinates {0, 0}, {0, 1} and {1, 1} have the value -1 attached to them and I want to plot them Red, the coordinate {1, 0} has the value 1 attached to it, so I want to plot it Blue and so on. How can I do this?

• So in value, a tuple {a, b, c} denotes a point {b, c} with color determined by a? – C. E. Jan 25 '17 at 18:35
• No, the table {{{a,b},{c,d}},{{e,f},{g,h}}} generated by position denotes the points {a,b}, {b,c}, {e,f} and {g,h} and value generates the corresponding values {{i,j},{k,l}}. So for example the value i corresponds to {a,b}, the value j to {c,d} and so on. – freddy90 Jan 25 '17 at 18:45
• Something like Graphics[{PointSize[Medium], MapThread[{#2 /. {-1 -> Red, 1 -> Blue}, Point[#]} &, {position, value}, 2]}], then? – J. M. will be back soon Jan 25 '17 at 18:49

I'd use Style:

position = Table[{i, j}, {i, -1, 1}, {j, -1, 1}];
value = {{1, -1, -1}, {1, 1, -1}, {1, 1, -1}};

data = Style[{#1, #2}, If[#3 == -1, Red, Blue]] & @@@ (* coloring *)
Flatten /@ Transpose@{Catenate@position, Catenate@value} (* I find this data
structure convenient *) ListPlot[data, Frame -> True, PlotStyle -> PointSize[Large]] Or

red  = Catenate@Pick[position, value, -1]
blue = Catenate@Pick[position, value, 1]

ListPlot[{red, blue}, Frame -> True,
PlotStyle -> {Directive[PointSize[Large], Red],
Directive[PointSize[Large], Blue]}]


plot as above

There are many solutions. Here is mine:

Graphics[{
PointSize[Large],
Point[
Flatten[position,1],
VertexColors->Replace[Flatten@value,{-1->Red,1->Blue},1]
]
}]