Coloring specific points with a different color in

2019-04-23 14:32发布

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?

3条回答
走好不送
2楼-- · 2019-04-23 14:51

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]]
查看更多
叼着烟拽天下
3楼-- · 2019-04-23 15:04

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

查看更多
够拽才男人
4楼-- · 2019-04-23 15:05

yoda shows a fine method. Sometimes however, it is easier to work directly with graphics primitives. Here is an example of that, though in this case I would choose yoda's method.

Graphics3D[{
  PointSize[0.02],
  Point /@ Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}] /. 
    x : _@{1, 2, 0} | _@{0, 0, 0} :> Style[x, Red]
}]
查看更多
登录 后发表回答