Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
早恵香
早恵香 el 16 de Nov. de 2023
Comentada: 早恵香 el 17 de Nov. de 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) % 系統樹を作成

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 16 de Nov. de 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 comentario
早恵香
早恵香 el 17 de Nov. de 2023
Thank you for your answer. I'll try using the method above.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Biological and Health Sciences en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!