필터 지우기
필터 지우기

How can I extract a colormap from a dendrogram?

조회 수: 3 (최근 30일)
Rebecca Ward
Rebecca Ward 2020년 10월 1일
댓글: Rebecca Ward 2020년 11월 24일
Hi, I have created a dendrogram and am happy with the colors it has selected by default. I want to create other plots using the same colormap to facilitate comparison. How do I extract the colormap from the dendrogram I have created?

채택된 답변

Jing Ci Neo
Jing Ci Neo 2020년 11월 12일
편집: Jing Ci Neo 2020년 11월 24일
Hello Rebecca,
I have a brute force solution for a few clusters. It looks like 'dendrogram' use the hsv colormap, and clusters with only 1 member are set to be black. The rest of the clusters are colored from
So what you can do is:
% Clustering
nClus = 10; % Let's say you have 10 clusters
clustTreeEuc = linkage(eucD,'average'); % By average euclidean distance
color = clustTreeEuc(end-nClus+2,3)-eps; % Calc. threshold based on nClus
[H,T,perm] = dendrogram(clustTreeEuc,0,'Orientation','right','ColorThreshold',...
color,'labels','myDataNames'); % Plot dendrogram
hidx = cluster(clustTreeEuc,'criterion','distance',...
'MaxClust',nClus); % idx of data in each clus
% After you plot the dendrogram, find out what color each cluster is
% You can use histcounts(hidx) to help you
% By the order of the rainbow (r y g b ...) assign each cluster a new number
% For e.g. clus 1 is green, new no. is 3. Clus 2 is red, new no. is 1 etc.
% Black is the last color (clusters with 1 member)
cidx = [4 1 7 3 8 2 6 5 9 9]; % Example with two 1 member clusters (so 9 colors)
% Colors
cmap = hsv(max(cidx)-1);
cmap(end+1,:) = [0 0 0];
cmap(cidx(hidx(i)),:) % This gives color of ith data
Hope it helps! If anyone finds a better method please let me know, thanks!
  댓글 수: 1
Rebecca Ward
Rebecca Ward 2020년 11월 24일
Thankyou - this is really helpful. I've been doing it manually by selecting a line and inspecting the color which is OK for a small dendrogram but this is better :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rishik Ramena
Rishik Ramena 2020년 10월 7일
편집: Rishik Ramena 2020년 10월 7일
You could use the ColorThreshold argument to specify the number of colors to be used in the dendrogram. This would then limit the use of newer colors in the different plots you seek to compare. You can also set the colors of the lines individually using the handles returned by the dendrogram function. Check here for examples and implementation.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by