在Mathematica中使用不同颜色着色特定点

smi*_*dha 8 wolfram-mathematica colors

Mathematica命令的输出

ListPointPlot3D[
  Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}], 
  PlotStyle -> PointSize[0.02]]
Run Code Online (Sandbox Code Playgroud)

是下图.

在此输入图像描述

我想用红色为点(0,0)和(1,2)着色.如何为此修改上述命令?

WRe*_*ach 12

可以使用以下ColorFunction选项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]
Run Code Online (Sandbox Code Playgroud)

两点着色

包含该ColorFunctionScaling -> False选项很重要,否则传递给颜色函数的x,yz坐标将被归一化到01的范围内.

ColorFunction 还允许我们使用任意计算定义点着色,例如:

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]
Run Code Online (Sandbox Code Playgroud)

许多点着色


abc*_*bcd 10

一个非常简单明了的方法是:

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]]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当然,我没有明确指定颜色就离开了它,因为下一个默认颜色是红色.但是,如果要指定自己的,可以将其修改为:

ListPointPlot3D[{Complement[list, pts], pts}, 
 PlotStyle -> {{Green, #}, {Blue, #}} &@PointSize[0.02]]
Run Code Online (Sandbox Code Playgroud)


Mr.*_*ard 6

尤达显示了一个很好的方法.但有时,直接使用图形基元更容易.这是一个例子,虽然在这种情况下我会选择yoda的方法.

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]
}]
Run Code Online (Sandbox Code Playgroud)