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)
0 个评论
采纳的回答
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!