2011-12-22 83 views
6

我遇到了一个问题,我需要使用不同颜色和标记绘制二维数据。如何绘制不同颜色和标记的2D数据

我们给出与2阵列,即(N×2维)和标签为(N×1周的尺寸)。我不知道标签阵列中唯一值的数量,但最大可能是10.我想绘制与不同的颜色和标记基于其相应的标签值。

任何一个可以帮助我在这方面

+2

可能重复(http://stackoverflow.com/questions/8533136/conditional-scatter-in-matlab) – yuk 2011-12-22 05:49:10

回答

10

使用gscatter,这确实散点图,(在你的情况Label)使用一组不同的颜色/制造商密谋。

GSCATTER(X,Y,G,CLR,SYM,SIZ) specifies the colors, markers, and 
    size to use. CLR is either a string of color specifications or 
    a three-column matrix of color specifications. SYM is a string 
    of marker specifications. Type "help plot" for more information. 
    For example, if SYM='o+x', the first group will be plotted with a 
    circle, the second with plus, and the third with x. SIZ is a 
    marker size to use for all plots. By default, the marker is '.'. 

所以,你可以指定颜色,如'rgcmykwb'为第一组做的红,绿,第二等或[]只是有Matlab的排序出来。

默认情况下,Matlab对每个组使用相同的标记,因此您需要指定要为每个组使用哪些标记。如果你做'.ox+*sdv^<>ph',你只需循环Matlab所有的标记。

n=50; 
% make nx2 matrix of random points. 
points = random('unif',0,1,n,2); 
% make nx1 matrix of random labels from {1,2,...,5} 
labels=round(random('unif',1,5,n,1)); 

% plot. Let Matlab sort out the colours and we will specify markers. 
gscatter(points(:,1),points(:,2),labels,[],'ox+*sdv^<>ph.') 

它看起来有点像这样: enter image description here

[在MATLAB条件散射]的
相关问题