【问题标题】:How to change the cluster colours in a dendrogram如何更改树状图中的簇颜色
【发布时间】:2016-04-29 03:49:18
【问题描述】:

如何更改分配给 MATLAB 树状图中每个集群的颜色以匹配我自己的自定义配色方案?广泛的谷歌搜索没有产生解决方案。

【问题讨论】:

    标签: matlab plot cluster-analysis hierarchical-clustering dendrogram


    【解决方案1】:
    %%// Hierarchical clustering
    T = linkage(data,'average','spearman');
    D = pdist(data, 'spearman');
    leafOrder = optimalleaforder(T, D);
    th = 0.726;
    H = dendrogram(T, 0,'ReOrder', leafOrder, 'Orientation', 'left', 'ColorThreshold', th);
    h = gca;
    set(h, 'YTickLabel', labels(leafOrder));
    
    %// Changing the colours
    lineColours = cell2mat(get(H,'Color'));
    colourList = unique(lineColours, 'rows');
    
    myColours = [230,186,0;
                 127,127,127;
                 10,35,140;
                 176,0,0;
                 158,182,72;
                 79,129,189;
                 209,99,9;
                 4,122,146]/255;
    
    %// Replace each colour (colour by colour). Start from 2 because the first colour are the "unclustered" black lines             
    for colour = 2:size(colourList,1)
        %// Find which lines match this colour
        idx = ismember(lineColours, colourList(colour,:), 'rows');
        %// Replace the colour for those lines
        lineColours(idx, :) = repmat(myColours(colour-1,:),sum(idx),1);
    end
    %// Apply the new colours to the chart's line objects (line by line)
    for line = 1:size(H,1)
        set(H(line), 'Color', lineColours(line,:));
    end
    

    【讨论】:

      猜你喜欢
      • 2016-07-06
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 2019-01-15
      • 2013-06-18
      • 1970-01-01
      相关资源
      最近更新 更多