필터 지우기
필터 지우기

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

조회 수: 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!