如果我有
matrix=
0.0494 2.3691
-0.0973 0.8026
-0.3040 -0.0861
-0.0626 2.5688
-0.4144 0.7054
0.0633 -0.0991
-0.8386 -1.2229
1.8929 2.6260
1.7687 2.3963
1.8243 -0.5543
1.9272 -0.3946
-0.0682 1.7404
-0.1180 2.2323
0.4071 -0.1878
0.6406 2.5602
-0.2144 2.0014
0.1091 -0.1874
-0.1102 0.2922
Run Code Online (Sandbox Code Playgroud)
你如何用一种颜色绘制一列,用另一种颜色绘制其他颜色,或者用一种颜色绘制其中一些
scatter(matrix(:,1),matrix(:,2), 'b','+');
Run Code Online (Sandbox Code Playgroud)
scatter不会单独绘制每列.这是column 1VS column 2.因此,散点图上的每个点都由两列组成.换句话说,scatter(x,y)和之间没有区别plot(x,y,'o').但是,scatter还有其他功能,这就是为什么它可以作为一个不同的功能.如果你只是试图用两种颜色分别绘制每一列,你可以简单地做plot(matrix,'o'),MATLAB应该自动为第一列分配蓝色,为第二列分配绿色.
scatter还将色图作为参数.因此,如果您打算将一半数据(两列)绘制为一种颜色而其他颜色另一种颜色,则可以尝试这样做
nRows=size(matrix,1);
red=repmat([1,0,0],fix(nRows/2),1);%# use fix so that you don't get an error if nRows is not even.
green=repmat([0,1,0],nRows-fix(nRows/2),1);
scatter(matrix(:,1),matrix(:,2),[],[red;green]);
Run Code Online (Sandbox Code Playgroud)