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

조회 수: 9 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by