フィルターのクリア

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

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 Center および File ExchangeBehavior and Psychophysics についてさらに検索

Community Treasure Hunt

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

Start Hunting!