2013-10-18 15 views

回答

1

最簡單的方法是分別繪製組,並指定每組不同的符號即

plot(x(Y<=90),Y(Y<=90),'bx',x(Y>90),Y(Y>90),'bo'); 
1

你也可以做不同的顏色。 scatter函數能夠爲每個點指定一個不同的顏色,其語法爲scatter(x,y,s,c)。對於你的榜樣,你可以這樣做:

% make data 
rng(0,'twister'); theta = linspace(0,2*pi,150); 
x = sin(theta) + 0.75*rand(1,150); x = x*100; 
y = cos(theta) + 0.75*rand(1,150); y = y*100; 
mask = y>90; 

% plot with custom colors for each point 
c = zeros(numel(x),3); % matrix of RGB colorspecs 
c(mask,:) = repmat([1 0 0],nnz(mask),1); % red 
c(~mask,:) = repmat([0 0 1],nnz(~mask),1); % blue 
scatter(x,y,10,c,'+'); 

或代替和RGB矩陣colorspec,你可以索引到當前顏色表。這可以讓你得到一些值一個很好的平滑變化:

scatter(x,y,10,y+x,'o') % x+y is mapped to indexes into default colormap, jet(64) 

您可以將數據分爲兩組也得到了不同標記的方法結合這個顏色映射。分割數據,如上所示用scatter繪製第一組,hold on,並用不同的標記繪製第二組。例如,

cv = x+y; % or just y, but this is an interesting example 
scatter(x(mask),y(mask),10,cv(mask),'+'); 
hold on 
scatter(x(~mask),y(~mask),10,cv(~mask),'o'); 

結果是不同的標記樣式,其中使用'+'其中y>90'+'別處,和不同的顏色,其中顏色通過的cv=x+y值映射到當前的色彩映射表來確定。這裏的想法是看兩種不同的變化模式,但你可以使用cv=y

enter image description here

相關問題