我有一个矩阵点X
在 3 个维度中(X
is a Nx3
矩阵)并且这些点属于簇。它所属的簇由下式给出Nx1
vector 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
非常感谢你的帮助!
而不是使用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');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)