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

5 次查看(过去 30 天)
早恵香
早恵香 2023-11-16
评论: 早恵香 2023-11-17
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) % 系統樹を作成

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-11-16
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 个评论
早恵香
早恵香 2023-11-17
Thank you for your answer. I'll try using the method above.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Biological and Health Sciences 的更多信息

Community Treasure Hunt

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

Start Hunting!