如何使用不同的颜色和标记绘制2D数据

Lea*_*ner 6 matlab

我面临一个问题,我需要绘制具有不同颜色和标记的二维数据.

我们给出了2个数组,即(nx 2维)和Label(nx 1维).我不确定Label数组中唯一值的数量,但最大值可能是10.我想根据相应的Label值绘制具有不同颜色和标记的.

任何人都可以在这方面帮助我

mat*_*fee 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 '.'.
Run Code Online (Sandbox Code Playgroud)

因此,您可以指定颜色,例如'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.')
Run Code Online (Sandbox Code Playgroud)

看起来有点像这样: 在此输入图像描述