Azzera filtri
Azzera filtri

dendrogram関数の配色を任意のものにする

5 visualizzazioni (ultimi 30 giorni)
早恵香
早恵香 il 16 Nov 2023
Commentato: 早恵香 il 17 Nov 2023
dendrogram関数で作成した系統樹をクラスター毎に色分けするにあたって、自身で指定した配色にしたいのですが、どうすればいいのでしょうか。
今回使用するコードは以下の通りです。
load fisheriris
orgcolor = colororder('default'); % 配色の決定(この配色をクラスターに使用)
Z = linkage(meas,'average','chebychev'); % 階層クラスターツリーの作成
cutoff = median([Z(end-2,3) Z(end-1,3)]); % クラスターを3つに分けれるよう中間点でカット
dendrogram(Z,'ColorThreshold',cutoff) % 系統樹を作成

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 16 Nov 2023
dendrogram is basically a group of lines. Thus, you will have to change the color of each lines accordingly -
load fisheriris
%orgcolor = colororder('default'); % 配色の決定(この配色をクラスターに使用)
Z = linkage(meas,'average','chebychev'); % 階層クラスターツリーの作成
cutoff = median([Z(end-2,3) Z(end-1,3)]); % クラスターを3つに分けれるよう中間点でカット
%% Original Figure
figure
dendrogram(Z,'ColorThreshold',cutoff); % 系統樹を作成
%% Modified Figure
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
%define new colors
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
%Change the corresponding colors
for k = 1:size(or, 1)
arr = idx==k;
set(d(arr), 'Color', newcolors(k, :))
end
  1 Commento
早恵香
早恵香 il 17 Nov 2023
Thank you for your answer. I'll try using the method above.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Biological and Health Sciences in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!