Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloring specific points with a different color in Mathematica

The output of the Mathematica command

ListPointPlot3D[
  Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}], 
  PlotStyle -> PointSize[0.02]]

is the following image.

enter image description here

I want to color the points (0,0) and (1,2) with the color red. How do I modify the above command for this?

like image 391
smilingbuddha Avatar asked Oct 29 '11 02:10

smilingbuddha


2 Answers

One could use the ColorFunction option to ListPointPlot3D:

color[0, 0, _] = Red;
color[1, 2, _] = Red;
color[_, _, _] = Blue;

ListPointPlot3D[
  Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}], 
  PlotStyle -> PointSize[0.02],
  ColorFunction -> color, ColorFunctionScaling -> False]

two points coloured

It is important to include the ColorFunctionScaling -> False option because otherwise the x, y and z co-ordinates passed to the colour function will be normalized into the range 0 to 1.

ColorFunction also allows us to define point colouring using arbitrary computations, for example:

color2[x_, y_, _] /; x^2 + y^2 <= 9 = Red;
color2[x_, y_, _] /; Abs[x] == Abs[y] = Green;
color2[_, _, _] = Blue;

ListPointPlot3D[
  Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}], 
  PlotStyle -> PointSize[0.02],
  ColorFunction -> color2, ColorFunctionScaling -> False]

many points coloured

like image 171
WReach Avatar answered Sep 27 '22 21:09

WReach


A very simple and straightforward way would be:

list = Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}];
pts = {{0, 0, 0}, {1, 2, 0}};

ListPointPlot3D[{Complement[list, pts], pts}, 
 PlotStyle -> PointSize[0.02]]

enter image description here

Of course, I left it without explicitly specifying colors because the next default color is red. However, if you want to specify your own, you can modify it a little more as:

ListPointPlot3D[{Complement[list, pts], pts}, 
 PlotStyle -> {{Green, #}, {Blue, #}} &@PointSize[0.02]]
like image 35
abcd Avatar answered Sep 27 '22 20:09

abcd