4

X3 次元の行列ポイント(XNx3行列) があり、それらのポイントはクラスターに属しています。属するクラスターは、Nx1ベクトルで指定されClusterます (1、2、3、... のような値を持ちます)。だから、私はそれをscatter3次のようにプロットしています:

scatter3(X(:,1),X(:,2),X(:,3),15,Cluster)

正常に動作しますが、凡例を追加して、色付きのマーカーとそれが表すクラスターを表示したいと思います。

たとえば、3 つのクラスターがある場合、次のような凡例が必要です。

<blue o> - Cluster 1
<red o> - Cluster 2
<yellow o> - Cluster 3

助けてくれてどうもありがとう!

4

2 に答える 2

3

を使用する代わりに、 をscatter3使用することをお勧めしますplot3。これにより、ラベル付けがはるかに簡単になります。

%# find out how many clusters you have
uClusters = unique(Cluster);
nClusters = length(uClusters);

%# create colormap
%# distinguishable_colormap from the File Exchange 
%# is great for distinguishing groups instead of hsv
cmap = hsv(nClusters);

%# plot, set DisplayName so that the legend shows the right label
figure,hold on
for iCluster = 1:nClusters
    clustIdx = Cluster==uClusters(iCluster);
    plot3(X(clustIdx,1),X(clustIdx,2),X(clustIdx,3),'o','MarkerSize',15,...
       'DisplayName',sprintf('Cluster %i',uClusters(iCluster)));
end

legend('show');
于 2012-12-22T22:22:20.440 に答える
1

あなたが使用するか

  • legend

コード:

h = scatter3(X(:,1),X(:,2),X(:,3),15,Cluster)
hstruct = get(h);
legend(hstruct.Children, "Cluster1", "Cluster2", "Cluter3");

また

于 2012-12-22T21:59:46.677 に答える