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

3 次查看(过去 30 天)
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 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by