フィルターのクリア

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 Center および File ExchangeBiological and Health Sciences についてさらに検索

Community Treasure Hunt

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

Start Hunting!