Effacer les filtres
Effacer les filtres

Dendrogram with colouring.

10 vues (au cours des 30 derniers jours)
Alice K
Alice K le 14 Août 2023
Commenté : Alice K le 14 Août 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.

Réponse acceptée

Adam Danz
Adam Danz le 14 Août 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)
ans = 4×3
1.0000 0 0 0.5000 1.0000 0 0 1.0000 1.0000 0.5000 0 1.0000
But if there were 5 colors, green would change to [0.8 1 0].
hsv(5)
ans = 5×3
1.0000 0 0 0.8000 1.0000 0 0 1.0000 0.4000 0 0.4000 1.0000 0.8000 0 1.0000
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])
  1 commentaire
Alice K
Alice K le 14 Août 2023
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by