Mathematica命令的输出
ListPointPlot3D[
Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}],
PlotStyle -> PointSize[0.02]]
如下图所示。
我想将点(0,0)和(1,2)涂成红色。如何修改上面的命令?
发布于 2011-10-29 11:05: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]]
发布于 2011-10-29 22:04:30
您可以使用ListPointPlot3D
的ColorFunction
选项
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坐标将被归一化到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]
发布于 2011-10-29 12:14:27
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]
}]
https://stackoverflow.com/questions/7936709
复制相似问题