Dendrogram with colouring.
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alice K
el 14 de Ag. de 2023
Comentada: Alice K
el 14 de Ag. de 2023
Hi All,
Hope to I remove certain colours from being used, I would like none of the cluster to be green.
Here is my code:
rng('default') % For reproducibility
X = rand(100,2);
tree = linkage(X,'average');
dendrogram(tree,"ColorThreshold",0.5)
Here my graph in question.
Thank you.
0 comentarios
Respuesta aceptada
Adam Danz
el 14 de Ag. de 2023
> How can I remove certain colours [of a dendrogram] from being used, I would like none of the cluster to be green.
Since you can't specify the colors directly, one approach would be to identify the lines that contain the undesired color and replace the color. However, "green" doesn't have a discrete definition so detecting green can be tricky. The colors are selected from hsv. In your example, there are 4 colors, and green is indicated by [0.5 1 0].
hsv(4)
But if there were 5 colors, green would change to [0.8 1 0].
hsv(5)
Since the hsv colormap does not get into dark green, we can loosely define green as RGB vectors that have a dominance in the G channel. Then we can replace all green-ish colors with a different color. NOTE if there are enough groups, there could be more than 1 cluster within the green-ish zone in which case this simple method would replace all of those groups with the same color in which case a more robust solution would be needed.
rng('default') % For reproducibility
X = rand(100,2);
tree = linkage(X,'average');
h = dendrogram(tree,"ColorThreshold",'default');
% List unique colors, ignore black
linecolors = vertcat(h.Color);
% Loosely determine which are green-ish
isGreenish = linecolors(:,2)./sum(linecolors,2) > .5;
% Replace greenish with magenta
set(h(isGreenish),'color',[1 0 1])
Más respuestas (0)
Ver también
Categorías
Más información sobre Red en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!