필터 지우기
필터 지우기

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!