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

时间:2011-10-29 02:56:16

标签: colors wolfram-mathematica

Mathematica命令的输出

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

是下图。

enter image description here

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

3 个答案:

答案 0 :(得分: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]

two points coloured

包含ColorFunctionScaling -> False选项很重要,否则将 x y z 坐标传递给颜色函数将被标准化为 0 1 的范围。

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]

many points coloured

答案 1 :(得分: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]]

enter image description here

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

ListPointPlot3D[{Complement[list, pts], pts}, 
 PlotStyle -> {{Green, #}, {Blue, #}} &@PointSize[0.02]]

答案 2 :(得分:6)

yoda显示了一个很好的方法。但有时,直接使用图形基元更容易。这是一个例子,虽然在这种情况下我会选择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]
}]