Mathematica命令的输出
ListPointPlot3D[
Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}],
PlotStyle -> PointSize[0.02]]
是下图。
我想用红色为点(0,0)和(1,2)着色。如何为此修改上述命令?
答案 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]
包含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]
答案 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]]
当然,我没有明确指定颜色就离开了它,因为下一个默认颜色是红色。但是,如果要指定自己的,可以将其修改为:
ListPointPlot3D[{Complement[list, pts], pts},
PlotStyle -> {{Green, #}, {Blue, #}} &@PointSize[0.02]]
答案 2 :(得分:6)
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]
}]