系統樹と散布図の色を連動させる方法

5 次查看(过去 30 天)
早恵香
早恵香 2023-11-17
评论: Dyuman Joshi 2023-11-18
系統樹と散布図の色を連動させるやり方はないのでしょうか。
参照となるコードは以下の通りです。
今回の質問内容を具体的に話せばf3の系統樹をf2の散布図と同じ配色にしたいのですが
load fisheriris
Z = linkage(meas,'average','chebychev'); % 階層クラスターツリーの作成
cutoff = median([Z(end-2,3) Z(end-1,3)]); % クラスターを3つに分けれるよう中間点でカット
f1 = figure;
ZCount = length(find(Z(:,3)>cutoff)) + 1;
[~,Zleaf] = dendrogram(Z,ZCount); % グループ分け
f2 = figure;
orgplot = gscatter(meas(:,1),meas(:,2),Zleaf); % 読み込んだデータをグラフ化して確認
%% 系統樹の出力
f3 = figure;
d = dendrogram(Z,'ColorThreshold',cutoff); % 系統樹を作成
Col = vertcat(d.Color);
[or, ~, idx] = unique(Col, 'rows')
or = 4×3
0 0 0 0 0 1 0 1 0 1 0 0
idx = 29×1
3 4 4 4 3 4 4 4 2 3
%配色を設定
newcolors = hsv(4)
newcolors = 4×3
1.0000 0 0 0.5000 1.0000 0 0 1.0000 1.0000 0.5000 0 1.0000
%設定した配色に変更
for k = 1:size(or, 1)
arr = idx==k;
set(d(arr), 'Color', newcolors(k, :))
end
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-18
There are 3 groups in the gscatter() whereas there are 4 groups in the dendrogram().
Which groups from the dendrogram should be similar to the gscatter? The bottom three (cyan, magenta and green lines in the above plot) ?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Behavior and Psychophysics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!