フィルターのクリア

Silhouette: How do I 'add' labels to bars and assign colors to each cluster

4 ビュー (過去 30 日間)
AR
AR 2022 年 11 月 11 日
コメント済み: AR 2022 年 11 月 20 日
Matlab SMEs,
Request help/advice:
1) Adding Labels to each bar on Silhouette
2) Assign different colors to each Silhouette bar or each cluster
My data, silTab.mat, attached & my attempts below.
Thank you.
--Allen
silLabels=SilTab.Properties.RowNames;
[ss sh]=silhouette(SilTab{:,1:20},SilTab{:,21},'Euclidean');
sh.Color=copper(length(sh)); % copper colormap for each bar
[ss sh]=silhouette(SilTab{:,1:20},SilTab{:,21},'Euclidean');
set(gca,{'Color'},num2cell(copper(length(sh)),2));
[ss sh]=silhouette(SilTab{:,1:20},SilTab{:,21},'Euclidean');
set(gca,'yticklabel',silLabels)

採用された回答

Vijay
Vijay 2022 年 11 月 14 日
Hello @AR
I am assuming by each cluster you mean different color for each bar. In a single bar graph you cannot do that, But there are workarounds.
Steps:
1. Extract data from current figure
2. Plot a new desired bar graph.
Step 1: Extracting Data
data = get(sh.CurrentAxes, 'Children');
x = get(data, 'XData');
y = get(data, 'YData');
Step2: Plotting graph.
Please refer to the link below on how to get different color for each bar.
For Adding labels to the graph please refer to the link below
Hope that helps!
  1 件のコメント
AR
AR 2022 年 11 月 20 日
VB, Thank you. This is exactly what I need. I did hope there was sinlge line of code that existed to color code the silhoutte output plot's bars, however this method works great. Best Regards, --Allen

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by