根据 Octave 中的向量对绘图上的颜色点进行着色
Color points on a plot according to a vector in Octave
我想绘制存储在 N-by-3 矩阵中的多个 2d 点。前两列定义 x 和 y 坐标。第 3 列定义要用于单个点的颜色索引,并引用如下颜色代码列表:
c={[1 0 0], [0 1 0], [0 0 1]}
然后调用绘图函数:
plot(points(:,1), points(:,2), '.', 'Color', c(points(:,3)));
但我只得到错误:
invalid value for color property "color"
有什么方法可以根据每个点的颜色绘制点吗?
为此使用 scatter
而不是绘图:
%// Making dummy data:
n = 10;
points = rand(n,2);
points(:,3) = randi(3,n,1);
%//Setting a colormap: note that you should not use a cell array for this!
c=[1 0 0; 0 1 0; 0 0 1]
colormap(c)
%//plot
scatter(points(:,1), points(:,2), [], points(:,3))
我想绘制存储在 N-by-3 矩阵中的多个 2d 点。前两列定义 x 和 y 坐标。第 3 列定义要用于单个点的颜色索引,并引用如下颜色代码列表:
c={[1 0 0], [0 1 0], [0 0 1]}
然后调用绘图函数:
plot(points(:,1), points(:,2), '.', 'Color', c(points(:,3)));
但我只得到错误:
invalid value for color property "color"
有什么方法可以根据每个点的颜色绘制点吗?
为此使用 scatter
而不是绘图:
%// Making dummy data:
n = 10;
points = rand(n,2);
points(:,3) = randi(3,n,1);
%//Setting a colormap: note that you should not use a cell array for this!
c=[1 0 0; 0 1 0; 0 0 1]
colormap(c)
%//plot
scatter(points(:,1), points(:,2), [], points(:,3))