matlab中 关于scatter plot 函数中颜色的问题

“帮助”中说scatter的颜色只有若干种(没弄错的化是8种不同颜色可用)

比如:

scatter(msdata(i,1),msdata(i,2),'.','y');

scatter(msdata(i,1),msdata(i,2),'.','g');

scatter(msdata(i,1),msdata(i,2),'.','w');

……

……

问题是,如果要用比较多的颜色来表示画出的点,用上述8种颜色俨然不够了

请问,这里的'y’,'g’等能否用一个RGB值来表示呢,

我试过比如scatter(msdata(i,1),msdata(i,2),'.',[0.1,0.3,0]); 这样貌似不行啊,

还有其他方法吗

scatter(X,Y,S,C) displays colored circles at the locations specified by the vectors X and Y (which must be the same size).

S determines the area of each marker (specified in points^2). S can be a vector the same length as X and Y or a scalar. If S is a scalar, MATLAB draws all the markers the same size. If S is empty, the default size is used.

C determines the color of each marker. When C is a vector the same length as X and Y, the values in C are linearly mapped to the colors in the current colormap. When C is a length(X)-by-3 matrix, it specifies the colors of the markers as RGB values. C can also be a color string (see ColorSpec for a list of color string specifiers).

上面的是help里面的话,里面说了When C is a length(X)-by-3 matrix,t specifies the colors of the markers as RGB values,也就是后面决定颜色的RGB不能只是一列数组,要是length(X)-by-3 matrix。

scatter(msdata(i,1),msdata(i,2),'.',[0.1,0.3,0]); 可以改成
scatter(msdata(i,1),msdata(i,2),'.',ones(length(msdata(i,1)))*[0.1,0.3,0]);
自己揣摩下试试
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-08
x = rand(1,10)*10;
y = rand(1,10)*10;;
z =rand(1,10)*10;;
t = round(sqrt(z))*35; %控制点大小
c = mod(round(z+2),255)/255; %控制点颜色,c可以是大于0小于1的值,与x同尺寸;可以是M-by-3 matrix(即RGB色彩格式);
scatter(x,y,t,c,'filled');本回答被网友采纳
相似回答