MATLAB | 这些美丽大方的弦图居然都是用MATLAB画的?

什么?这些美丽大方的弦图都是MATLAB画的???

没错都是由我本人开发的弦图绘制工具包实现的:

  • chord chart 弦图https://www.mathworks.com/matlabcentral/fileexchange/116550-chord-chart
  • Digraph chord chart 有向弦图 https://www.mathworks.com/matlabcentral/fileexchange/121043-digraph-chord-chart

这俩工具包可以去链接所示地址下载,也可去文末所示的gitee仓库下载,本期只展示怎么调用函数绘图,篇幅问题就不把工具函数进行展示了,请自行下载工具包。当然也可以直接去文末所示gitee仓库下载整和好的全部文件。

编写本篇文章的原因是,已经由很多人开始使用我开发的弦图绘制工具,但是对一些样式能不能设置不太了解,作为开发者也算是比较了解工具的实现原理,能比较灵活的运用,于是就萌生了挑战绘制各种样式弦图的想法,目前有的代码并不算短,未来有可能我会将一部分代码集成进工具里,让大家能够一两行代码实现以下好多行代码的效果。废话不多说,来看这个MATLAB工具包当前版本能做到什么程度叭:


弦图 1


rng(2)

dataMat = randi([0,5], [11,5]);
dataMat(1:6,1) = 0;
dataMat([11,7],1) = [45,25];
dataMat([1,4,5,7],2) = [20,20,30,30];
dataMat(:,3) = 0;
dataMat(6,3) = 45;
dataMat(1:5,4) = 0;
dataMat([6,7],4) = [25,25];
dataMat([5,6,9],5) = [25,25,25];

colName = {'Fly', 'Beetle', 'Leaf', 'Soil', 'Waxberry'};
rowName = {'Bartomella', 'Bradyrhizobium', 'Dysgomonas', 'Enterococcus',...
           'Lactococcus', 'norank', 'others', 'Pseudomonas', 'uncultured',...
           'Vibrionimonas', 'Wolbachia'};

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80);
CC = CC.draw();
% 修改上方方块颜色(Modify the color of the blocks above)
CListT = [0.7765 0.8118 0.5216; 0.4431 0.4706 0.3843; 0.5804 0.2275 0.4549;
          0.4471 0.4039 0.6745; 0.0157 0      0     ];
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',CListT(i,:))
end
% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [0.5843 0.6863 0.7843; 0.1098 0.1647 0.3255; 0.0902 0.1608 0.5373;
          0.6314 0.7961 0.2118; 0.0392 0.2078 0.1059; 0.0157 0      0     ;
          0.8549 0.9294 0.8745; 0.3882 0.3255 0.4078; 0.5020 0.7216 0.3843;
          0.0902 0.1843 0.1804; 0.8196 0.2314 0.0706];
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListT(j,:), 'FaceAlpha',.5)
    end
end

CC.tickState('on')
CC.labelRotate('on')
CC.setFont('FontSize',17, 'FontName','Cambria')


% CC.labelRotate('off')
% textHdl = findobj(gca,'Tag','ChordLabel');
% for i = 1:length(textHdl)
%     if textHdl(i).Position(2) < 0
%         if abs(textHdl(i).Position(1)) > .7
%             textHdl(i).Rotation = textHdl(i).Rotation + 45;
%             textHdl(i).HorizontalAlignment = 'right';
%             if textHdl(i).Rotation > 90
%                 textHdl(i).Rotation = textHdl(i).Rotation + 180;
%                 textHdl(i).HorizontalAlignment = 'left';
%             end
%         else
%             textHdl(i).Rotation = textHdl(i).Rotation + 10;
%             textHdl(i).HorizontalAlignment = 'right';
%         end
%     end
% end

弦图 2

rng(3)
dataMat = randi([1,15], [7,22]);
dataMat(dataMat < 11) = 0;
dataMat(1, sum(dataMat, 1) == 0) = 15;
colName = {'A2M', 'FGA', 'FGB', 'FGG', 'F11', 'KLKB1', 'SERPINE1', 'VWF',...
           'THBD', 'TFPI', 'PLAT', 'SERPINA5', 'SERPIND1', 'F2', 'PLG', 'F12',...
           'SERPINC1', 'SERPINA1', 'PROS1', 'SERPINF2', 'F13A1', 'PROC'};
rowName = {'Lung', 'Spleen', 'Liver', 'Heart',...
           'Renal cortex', 'Renal medulla', 'Thyroid'};

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80, 'LRadius',1.21);
CC = CC.draw();
CC.labelRotate('on')

% 单独设置每一个弦末端方块(Set individual end blocks for each chord)
% Use obj.setEachSquareF_Prop 
% or  obj.setEachSquareT_Prop
% F means from (blocks below)
% T means to   (blocks above)
CListT = [173,70,65; 79,135,136]./255;
% Upregulated:1 | Downregulated:2
Regulated = rand([7, 22]);
Regulated = (Regulated < .8) + 1;
for i = 1:size(Regulated, 1)
    for j = 1:size(Regulated, 2)
        CC.setEachSquareT_Prop(i, j, 'FaceColor', CListT(Regulated(i,j),:))
    end
end
% 绘制图例(Draw legend)
H1 = fill([0,1,0] + 100, [1,0,1] + 100, CListT(1,:), 'EdgeColor','none');
H2 = fill([0,1,0] + 100, [1,0,1] + 100, CListT(2,:), 'EdgeColor','none');
lgdHdl = legend([H1,H2], {'Upregulated','Downregulated'}, 'AutoUpdate','off', 'Location','best');
lgdHdl.ItemTokenSize = [12,12];
lgdHdl.Box = 'off';
lgdHdl.FontSize = 13;

% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [128,108,171; 222,208,161; 180,196,229; 209,150,146; 175,201,166;
          134,156,118; 175,175,173]./255;
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListF(i,:), 'FaceAlpha',.45)
    end
end

弦图 3

dataMat = rand([15,15]);
dataMat(dataMat > .15) = 0;

CList = [ 75,146,241; 252,180, 65; 224, 64, 10;   5,100,146; 191,191,191;
          26, 59,105; 255,227,130;  18,156,221; 202,107, 75;   0, 92,219;
         243,210,136;  80, 99,129; 241,185,168; 224,131, 10; 120,147,190]./255;

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();

% 添加刻度
BCC.tickState('on')

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17, 'Color',[0,0,.8])

弦图 4


rng(5)
dataMat = randi([1,20], [5,5]);
dataMat(1,1) = 110;
dataMat(2,2) = 40;
dataMat(3,3) = 50;
dataMat(5,5) = 50;

CList1 = [164,190,158; 216,213,153; 177,192,208; 238,238,227; 249,217,153]./255;
CList2 = [247,204,138; 128,187,185; 245,135,124; 140,199,197; 252,223,164]./255;
CList = CList2;
NameList={'CHORD','CHART','MADE','BY','SLANDARER'};

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList, 'Sep',1/30, 'Label',NameList, 'LRadius',1.33);
BCC = BCC.draw();

% 添加刻度
BCC.tickState('on')

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.7, 'EdgeColor',CList(i,:)./1.1)
        end
    end
end
% 修改方块颜色(Modify the color of the blocks)
for i = 1:size(dataMat, 1)
    BCC.setSquareN(i, 'EdgeColor',CList(i,:)./1.7)
end

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17)
BCC.tickLabelState('on')
BCC.setTickFont('FontName','Cambria', 'FontSize',9)

弦图 5

dataMat=randi([1,20], [14,3]);
dataMat(11:14,1) = 0;
dataMat(6:10,2) = 0;
dataMat(1:5,3) = 0;

colName =  compose('C%d', 1:3);
rowName = [compose('A%d', 1:7), compose('B%d', 7:-1:1)];

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80);
CC = CC.draw();

% 修改上方方块颜色(Modify the color of the blocks above)
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',[190,190,190]./255)
end
% 修改下方方块颜色(Modify the color of the blocks below)
CListF=[255,244,138; 253,220,117; 254,179, 78; 253,190, 61;
        252, 78, 41; 228, 26, 26; 178,  0, 36;   4, 84,119;
          1,113,137;  21,150,155;  67,176,173;  68,173,158;
        123,204,163; 184,229,162]./255;
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListF(i,:), 'FaceAlpha',.5)
    end
end


CC.tickState('on')
CC.tickLabelState('on')

弦图 6

rng(2)

dataMat = randi([0,40], [20,4]);
dataMat(rand([20,4]) < .2) = 0;
dataMat(1,3) = 500;
dataMat(20,1:4) = [140; 150; 80; 90];

colName = compose('T%d', 1:4);
rowName = compose('SL%d', 1:20);

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80, 'LRadius',1.23);
CC = CC.draw();
% 修改上方方块颜色(Modify the color of the blocks above)
CListT = [0.62,0.49,0.27; 0.28,0.57,0.76
          0.25,0.53,0.30; 0.86,0.48,0.34];
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',CListT(i,:))
end
% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [0.94,0.84,0.60; 0.16,0.50,0.67; 0.92,0.62,0.49;
    0.48,0.44,0.60; 0.48,0.44,0.60; 0.71,0.79,0.73;
    0.96,0.98,0.98; 0.51,0.82,0.95; 0.98,0.70,0.82;
    0.97,0.85,0.84; 0.55,0.64,0.62; 0.94,0.93,0.60;
    0.98,0.90,0.85; 0.72,0.84,0.81; 0.85,0.45,0.49;
    0.76,0.76,0.84; 0.59,0.64,0.62; 0.62,0.14,0.15;
    0.75,0.75,0.75; 1.00,1.00,1.00];
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
CC.setSquareF_N(size(dataMat, 1), 'EdgeColor','k', 'LineWidth',1)
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListT(j,:), 'FaceAlpha',.46)
    end
end

CC.tickState('on')
CC.labelRotate('on')
CC.setFont('FontSize',17, 'FontName','Cambria')

弦图 7

dataMat = randi([10,10000], [10,10]);
dataMat(6:10,:) = 0;
dataMat(:,1:5) = 0;

NameList = {'BOC', 'ICBC', 'ABC', 'BOCM', 'CCB', ...
            'yama', 'nikoto', 'saki', 'koto', 'kawa'};
CList = [0.63,0.75,0.88
    0.67,0.84,0.75
    0.85,0.78,0.88
    1.00,0.92,0.93
    0.92,0.63,0.64
    0.57,0.67,0.75
    1.00,0.65,0.44
    0.72,0.73,0.40
    0.65,0.57,0.58
    0.92,0.94,0.96];

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList, 'Label',NameList);
BCC = BCC.draw();

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.85, 'EdgeColor',CList(i,:)./1.5, 'LineWidth',.8)
        end
    end
end
for i = 1:size(dataMat, 1)
    BCC.setSquareN(i, 'EdgeColor',CList(i,:)./1.5, 'LineWidth',1)
end


% 添加刻度、修改字体
BCC.tickState('on')
BCC.setFont('FontName','Cambria', 'FontSize',17)

弦图 8

dataMat = rand([11,4]);
dataMat = round(10.*dataMat.*((11:-1:1).'+1))./10;

colName = {'A','B','C','D'};
rowName = {'Acidobacteriota', 'Actinobacteriota', 'Proteobacteria', ...
           'Chloroflexi', 'Bacteroidota', 'Firmicutes', 'Gemmatimonadota', ...
           'Verrucomicrobiota', 'Patescibacteria', 'Planctomyetota', 'Others'};

figure('Units','normalized', 'Position',[.02,.05,.8,.85])
CC = chordChart(dataMat, 'colName',colName, 'Sep',1/80, 'SSqRatio',30/100);% -30/100
CC = CC.draw();

% 修改上方方块颜色(Modify the color of the blocks above)
CListT = [0.93,0.60,0.62
    0.55,0.80,0.99
    0.95,0.82,0.18
    1.00,0.81,0.91];
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',CListT(i,:))
end

% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [0.75,0.73,0.86
    0.56,0.83,0.78
    0.00,0.60,0.20
    1.00,0.49,0.02
    0.78,0.77,0.95
    0.59,0.24,0.36
    0.98,0.51,0.45
    0.96,0.55,0.75
    0.47,0.71,0.84
    0.65,0.35,0.16
    0.40,0.00,0.64];
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end

% 修改弦颜色(Modify chord color)
CListC = [0.55,0.83,0.76
    0.75,0.73,0.86
    0.00,0.60,0.19
    1.00,0.51,0.04];
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListC(j,:), 'FaceAlpha',.4)
    end
end

% 单独设置每一个弦末端方块(Set individual end blocks for each chord)
% Use obj.setEachSquareF_Prop 
% or  obj.setEachSquareT_Prop
% F means from (blocks below)
% T means to   (blocks above)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setEachSquareT_Prop(i,j, 'FaceColor', CListF(i,:))
    end
end

% 添加刻度
CC.tickState('on')

% 修改字体,字号及颜色
CC.setFont('FontName','Cambria', 'FontSize',17)

% 隐藏下方标签
textHdl = findobj(gca, 'Tag','ChordLabel');
for i = 1:length(textHdl)
    if textHdl(i).Position(2) < 0
        set(textHdl(i), 'Visible','off')
    end
end

% 绘制图例(Draw legend)
scatterHdl = scatter(10.*ones(size(dataMat,1)),10.*ones(size(dataMat,1)), ...
                     55, 'filled');
for i = 1:length(scatterHdl)
    scatterHdl(i).CData = CListF(i,:);
end
lgdHdl = legend(scatterHdl, rowName, 'Location','best', 'FontSize',16, 'FontName','Cambria', 'Box','off');
set(lgdHdl, 'Position',[.7482,.3577,.1658,.3254])

弦图 9


dataMat = randi([0,10], [5,5]);

CList1 = [0.70,0.59,0.67
    0.62,0.70,0.62
    0.81,0.75,0.62
    0.80,0.62,0.56
    0.62,0.65,0.65];
CList2 = [0.02,0.02,0.02
    0.59,0.26,0.33
    0.38,0.49,0.38
    0.03,0.05,0.03
    0.29,0.28,0.32];
CList = CList2;

NameList={'CHORD','CHART','MADE','BY','SLANDARER'};

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList, 'Sep',1/30, 'Label',NameList, 'LRadius',1.33);
BCC = BCC.draw();

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        BCC.setChordMN(i,j, 'FaceAlpha',.5)
    end
end
% 修改方块颜色(Modify the color of the blocks)
for i = 1:size(dataMat, 1)
    BCC.setSquareN(i, 'EdgeColor',[0,0,0], 'LineWidth',5)
end

% 添加刻度
BCC.tickState('on')
% 修改字体,字号及颜色
BCC.setFont('FontSize',17, 'FontWeight','bold')
BCC.tickLabelState('on')
BCC.setTickFont('FontSize',9)

弦图 10



rng(2)
dataMat = rand([14,5]) > .3;

colName = {'phosphorylation', 'vasculature development', 'blood vessel development', ...
           'cell adhesion', 'plasma membrane'};
rowName = {'THY1', 'FGF2', 'MAP2K1', 'CDH2', 'HBEGF', 'CXCR4', 'ECSCR',...
           'ACVRL1', 'RECK', 'PNPLA6', 'CDH5', 'AMOT', 'EFNB2', 'CAV1'};

figure('Units','normalized', 'Position',[.02,.05,.9,.85])
CC = chordChart(dataMat, 'colName',colName, 'rowName',rowName, 'Sep',1/80, 'LRadius',1.2);
CC = CC.draw();


% 修改上方方块颜色(Modify the color of the blocks above)
CListT1 = [0.5686    0.1961    0.2275
    0.2275    0.2863    0.3765
    0.8431    0.7882    0.4118
    0.4275    0.4510    0.2706
    0.3333    0.2706    0.2510];
CListT2 = [0.4941    0.5490    0.4118
    0.9059    0.6510    0.3333
    0.8980    0.6157    0.4980
    0.8902    0.5137    0.4667
    0.4275    0.2824    0.2784];
CListT3 = [0.4745    0.5843    0.7569
    0.4824    0.5490    0.5843
    0.6549    0.7216    0.6510
    0.9412    0.9216    0.9059
    0.9804    0.7608    0.6863];
CListT = CListT3;
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',CListT(i,:), 'EdgeColor',[0,0,0])
end
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListT(j,:), 'FaceAlpha',.9, 'EdgeColor',[0,0,0])
    end
end


% 修改下方方块颜色(Modify the color of the blocks below)
logFC = sort(rand(1,14))*6 - 3;
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'CData',logFC(i), 'FaceColor','flat', 'EdgeColor',[0,0,0])
end
CMap = [     0         0    1.0000; 0.0645    0.0645    1.0000; 0.1290    0.1290    1.0000; 0.1935    0.1935    1.0000
        0.2581    0.2581    1.0000; 0.3226    0.3226    1.0000; 0.3871    0.3871    1.0000; 0.4516    0.4516    1.0000
        0.5161    0.5161    1.0000; 0.5806    0.5806    1.0000; 0.6452    0.6452    1.0000; 0.7097    0.7097    1.0000
        0.7742    0.7742    1.0000; 0.8387    0.8387    1.0000; 0.9032    0.9032    1.0000; 0.9677    0.9677    1.0000
        1.0000    0.9677    0.9677; 1.0000    0.9032    0.9032; 1.0000    0.8387    0.8387; 1.0000    0.7742    0.7742
        1.0000    0.7097    0.7097; 1.0000    0.6452    0.6452; 1.0000    0.5806    0.5806; 1.0000    0.5161    0.5161
        1.0000    0.4516    0.4516; 1.0000    0.3871    0.3871; 1.0000    0.3226    0.3226; 1.0000    0.2581    0.2581
        1.0000    0.1935    0.1935; 1.0000    0.1290    0.1290; 1.0000    0.0645    0.0645; 1.0000         0         0];
colormap(CMap);
try clim([-3,3]),catch,end
try caxis([-3,3]),catch,end

CBHdl = colorbar();
CBHdl.Position = [0.74,0.25,0.02,0.2];

% =========================================================================
% 交换XY轴(Swap XY axis)
patchHdl = findobj(gca, 'Type','patch');
for i = 1:length(patchHdl)
    tX = patchHdl(i).XData;
    tY = patchHdl(i).YData;
    patchHdl(i).XData = tY;
    patchHdl(i).YData = - tX;
end
txtHdl = findobj(gca, 'Type','text');
for i = 1:length(txtHdl)
    txtHdl(i).Position([1,2]) = [1,-1].*txtHdl(i).Position([2,1]);
    if txtHdl(i).Position(1) < 0
        txtHdl(i).HorizontalAlignment = 'right';
    else
        txtHdl(i).HorizontalAlignment = 'left';
    end
end
lineHdl = findobj(gca, 'Type','line');
for i = 1:length(lineHdl)
    tX = lineHdl(i).XData;
    tY = lineHdl(i).YData;
    lineHdl(i).XData = tY;
    lineHdl(i).YData = - tX;
end
% =========================================================================

txtHdl = findobj(gca, 'Type','text');
for i = 1:length(txtHdl)
    if txtHdl(i).Position(1) > 0
        txtHdl(i).Visible = 'off';
    end
end

text(1.25,-.15, 'LogFC', 'FontSize',16)
text(1.25,1, 'Terms', 'FontSize',16)

patchHdl = [];
for i = 1:size(dataMat, 2)
    patchHdl(i) = fill([10,11,12],[10,13,13], CListT(i,:), 'EdgeColor',[0,0,0]);
end
lgdHdl = legend(patchHdl, colName, 'Location','best', 'FontSize',14, 'FontName','Cambria', 'Box','off');
lgdHdl.Position = [.735,.53,.167,.27];
lgdHdl.ItemTokenSize = [18,8];

弦图 11

rng(2)
dataMat = rand([12,12]);
dataMat(dataMat < .85) = 0;
dataMat(7,:) = 1.*(rand(1,12)+.1);
dataMat(11,:) = .6.*(rand(1,12)+.1);
dataMat(12,:) = [2.*(rand(1,10)+.1), 0, 0];

CList = [repmat([49,49,49],[10,1]); 235,28,34; 19,146,241]./255;

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','off', 'CData',CList);
BCC = BCC.draw();

% 添加刻度
BCC.tickState('on')

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17)

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.78, 'EdgeColor',[0,0,0])
        end
    end
end

% 修改方块颜色(Modify the color of the blocks)
for i = 1:size(dataMat, 1)
    BCC.setSquareN(i, 'EdgeColor',[0,0,0], 'LineWidth',2)
end

弦图 12

dataMat = rand([9,9]);
dataMat(dataMat > .7) = 0;
dataMat(eye(9) == 1) = (rand([1,9])+.2).*3;

CList = [0.85,0.23,0.24
0.96,0.39,0.18
0.98,0.63,0.22
0.99,0.80,0.26
0.70,0.76,0.21
0.24,0.74,0.71
0.27,0.65,0.84
0.09,0.37,0.80
0.64,0.40,0.84];

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();

% 添加刻度、刻度标签
BCC.tickState('on')

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17)


% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.7)
        end
    end
end

弦图 13

rng(2)

dataMat = randi([1,40], [7,4]);
dataMat(rand([7,4]) < .1) = 0;

colName = compose('MATLAB%d', 1:4);
rowName = compose('SL%d', 1:7);

figure('Units','normalized', 'Position',[.02,.05,.7,.85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80, 'LRadius',1.32);
CC = CC.draw();
% 修改上方方块颜色(Modify the color of the blocks above)
CListT = [0.49,0.64,0.53
    0.75,0.39,0.35
    0.80,0.74,0.42
    0.40,0.55,0.66];
for i = 1:size(dataMat, 2)
    CC.setSquareT_N(i, 'FaceColor',CListT(i,:))
end
% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [0.91,0.91,0.97
    0.62,0.95,0.66
    0.91,0.61,0.20
    0.54,0.45,0.82
    0.99,0.76,0.81
    0.91,0.85,0.83
    0.53,0.42,0.43];
for i = 1:size(dataMat, 1)
    CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        CC.setChordMN(i,j, 'FaceColor',CListT(j,:), 'FaceAlpha',.46)
    end
end

CC.tickState('on')
CC.tickLabelState('on')
CC.setFont('FontSize',17, 'FontName','Cambria')
CC.setTickFont('FontSize',8, 'FontName','Cambria')


% 绘制图例(Draw legend)
scatterHdl = scatter(10.*ones(size(dataMat,1)),10.*ones(size(dataMat,1)), ...
                     55, 'filled');
for i = 1:length(scatterHdl)
    scatterHdl(i).CData = CListF(i,:);
end
lgdHdl = legend(scatterHdl, rowName, 'Location','best', 'FontSize',16, 'FontName','Cambria', 'Box','off');
set(lgdHdl, 'Position',[.77,.38,.1658,.27])

弦图 14

rng(6)
dataMat = randi([1,20], [8,8]);
dataMat(dataMat > 5) = 0;
dataMat(1,:) = randi([1,15], [1,8]);
dataMat(1,8) = 40;
dataMat(8,8) = 60;

dataMat = dataMat./sum(sum(dataMat));

CList = [0.33,0.53,0.86
    0.94,0.50,0.42
    0.92,0.58,0.30
    0.59,0.47,0.45
    0.37,0.76,0.82
    0.82,0.68,0.29
    0.75,0.62,0.87
    0.43,0.69,0.57];
NameList={'CHORD', 'CHART', 'AND', 'BICHORD',...
    'CHART', 'MADE', 'BY', 'SLANDARER'};

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList, 'Sep',1/12, 'Label',NameList, 'LRadius',1.33);
BCC = BCC.draw();

% 添加刻度
BCC.tickState('on')

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.7, 'EdgeColor',CList(i,:)./1.1)
        end
    end
end
% 修改方块颜色(Modify the color of the blocks)
for i = 1:size(dataMat, 1)
    BCC.setSquareN(i, 'EdgeColor',CList(i,:)./1.7)
end

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17)
BCC.tickLabelState('on')
BCC.setTickFont('FontName','Cambria', 'FontSize',9)



% 调整数值字符串格式
% Adjust numeric string format
BCC.setTickLabelFormat(@(x)[num2str(round(x*100)),'%'])

弦图 15

CList = [0.81,0.72,0.83
0.69,0.82,0.89
0.17,0.44,0.64
0.70,0.85,0.55
0.03,0.57,0.13
0.97,0.67,0.64
0.84,0.09,0.12
1.00,0.80,0.46
0.98,0.52,0.01
    ];

figure('Units','normalized', 'Position',[.02,.05,.53,.85], 'Color',[1,1,1])

% =========================================================================
ax1 = axes('Parent',gcf, 'Position',[0,1/2,1/2,1/2]);
dataMat = rand([9,9]);
dataMat(dataMat > .4) = 0;
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();
BCC.tickState('on')
BCC.setFont('Visible','off')
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.6)
        end
    end
end
text(-1.2,1.2, 'a', 'FontName','Times New Roman', 'FontSize',35)

% =========================================================================
ax2 = axes('Parent',gcf, 'Position',[1/2,1/2,1/2,1/2]);
dataMat = rand([9,9]);
dataMat(dataMat > .4) = 0;
dataMat = dataMat.*(1:9);
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();
BCC.tickState('on')
BCC.setFont('Visible','off')
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.6)
        end
    end
end
text(-1.2,1.2, 'b', 'FontName','Times New Roman', 'FontSize',35)

% =========================================================================
ax3 = axes('Parent',gcf, 'Position',[0,0,1/2,1/2]);
dataMat = rand([9,9]);
dataMat(dataMat > .4) = 0;
dataMat = dataMat.*(1:9).';
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();
BCC.tickState('on')
BCC.setFont('Visible','off')
% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceAlpha',.6)
        end
    end
end
text(-1.2,1.2, 'c', 'FontName','Times New Roman', 'FontSize',35)

% =========================================================================
ax4 = axes('Parent',gcf, 'Position',[1/2,0,1/2,1/2]);
ax4.XColor = 'none'; ax4.YColor = 'none';
ax4.XLim = [-1,1]; ax4.YLim = [-1,1];
hold on

NameList = {'Food supply', 'Biodiversity', 'Water quality regulation', ...
            'Air quality regulation', 'Erosion control', 'Carbon storage', ...
            'Water retention', 'Recreation', 'Soil quality regulation'};
patchHdl = [];
for i = 1:size(dataMat, 2)
    patchHdl(i) = fill([10,11,12],[10,13,13], CList(i,:), 'EdgeColor',[0,0,0]);
end
lgdHdl = legend(patchHdl, NameList, 'Location','best', 'FontSize',14, 'FontName','Cambria', 'Box','off');
lgdHdl.Position = [.625,.11,.255,.27];
lgdHdl.ItemTokenSize = [18,8];

弦图 16


dataMat = rand([15,15]);
dataMat(dataMat > .2) = 0;

CList = [ 75,146,241; 252,180, 65; 224, 64, 10;   5,100,146; 191,191,191;
          26, 59,105; 255,227,130;  18,156,221; 202,107, 75;   0, 92,219;
         243,210,136;  80, 99,129; 241,185,168; 224,131, 10; 120,147,190]./255;
CListC = [54,69,92]./255;
CList = CList.*.6 + CListC.*.4;

figure('Units','normalized', 'Position',[.02,.05,.6,.85])
BCC = biChordChart(dataMat, 'Arrow','on', 'CData',CList);
BCC = BCC.draw();

% 添加刻度
BCC.tickState('on')

% 修改字体,字号及颜色
BCC.setFont('FontName','Cambria', 'FontSize',17, 'Color',[0,0,0])

% 修改弦颜色(Modify chord color)
for i = 1:size(dataMat, 1)
    for j = 1:size(dataMat, 2)
        if dataMat(i,j) > 0
            BCC.setChordMN(i,j, 'FaceColor',CListC ,'FaceAlpha',.07)
        end
    end
end
[~, N] = max(sum(dataMat > 0, 2));
for j = 1:size(dataMat, 2)
    BCC.setChordMN(N,j, 'FaceColor',CList(N,:) ,'FaceAlpha',.6)
end

gitee仓库

大家可以去Gitee仓库获取代码整合包:

  • https://gitee.com/slandarer/matlab-chord-chart

chordChart 弦图 fileexchange

Zhaoxu Liu / slandarer (2023). chord chart 弦图 (https://www.mathworks.com/matlabcentral/fileexchange/116550-chord-chart), MATLAB Central File Exchange. 检索来源 2023/4/1.

biChordChart 有向弦图 fileexchange

Zhaoxu Liu / slandarer (2023). Digraph chord chart 有向弦图 (https://www.mathworks.com/matlabcentral/fileexchange/121043-digraph-chord-chart), MATLAB Central File Exchange. 检索来源 2023/4/1.

未经许可代码不能做任何商务用途,引用可以引用上述fileexchange链接,引用时可改变引用文本格式,但至少应包含链接。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/533845.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【c语言】自定义类型:结构体详解

目录 自定义类型&#xff1a;结构体 结构体类型的声明 结构体变量的创建和初始化 结构的特殊声明 结构的自引用 结构体内存对齐 对其规则 为什么存在内存对齐&#xff1f; 修改默认对⻬数 结构体传参 结构体实现位段 位段的内存分配 位段的跨平台问题 位段的应用…

vue3新手笔记

setup&#xff08;&#xff09;{}函数&#xff0c;是启动页面后&#xff0c;自动执行的一个函数。所有数据&#xff08;常量、变量&#xff09;、函数等等&#xff0c;都要return 出去。 ref函数(可用于基本数据类型&#xff0c;也可以用于复杂数据类型)&#xff1a;让页面上的…

Java Set基础篇

目录 前言一、常用Set1.1 Set1.1.1 特点 1.2 HashSet1.2.1 特点1.2.2 使用 1.3 TreeSet1.3.1 特点1.3.2 使用 1.4 LinkedHashSet1.4.1 特点1.4.2 使用 二、对比总结 目录 前言 一、常用Set 1.1 Set Set是一个继承自Collection的接口&#xff1a; public interface Set<…

位图布隆过滤器的原理及实现

目录 位图的概念&#xff1a; 位图的前置知识&#xff1a;位运算 位图的实现&#xff1a; 位图的基本参数和构造方法&#xff1a; 位图的插入&#xff1a; 位图的查找&#xff1a; 位图的删除&#xff1a; 布隆过滤器概念&#xff1a; 布隆过滤器的实现&#xff1a; …

【软件测试之边界值法】

【软件测试之边界值法】(蓝桥杯学习笔记) 我们先来看一个 Java 小程序&#xff0c;如下图所示。 运行这个程序会发生什么事情呢&#xff1f;在这个程序中&#xff0c;目标是为了创建一个有 10 个元素的一维数组&#xff0c;但是&#xff0c;在 Java 语言中&#xff0c;当一个数…

win7无法升级win11,win7无法升级win11系统版本怎么解决

自动微软推出win11后,有不少小伙伴升级安装了。但是,有一些win7用户却安装win11失败,想知道有什么办法能让win7顺利升级win11。关于win7无法升级win11这个问题,最主要原因可能是你的电脑配置不够,毕竟升级win11的门槛要比升级win10还要高,而且还需要支持UEFI安全启动和TP…

Java项目:基于SSM+vue框架实现的人力资源管理系统设计与实现(源码+数据库+毕业论文+任务书)

一、项目简介 本项目是一套基于SSM框架实现的人力资源管理系统 包含&#xff1a;项目源码、数据库脚本等&#xff0c;该项目附带全部源码可作为毕设使用。 项目都经过严格调试&#xff0c;eclipse或者idea 确保可以运行&#xff01; 该系统功能完善、界面美观、操作简单、功能…

局域网tcp通信实验

两台windows系统计算机简单TCP通信测试_两台计算机tcp通信-CSDN博客 使用这篇文章的小工具。 环境&#xff1a; 我和同学的两台笔记本电脑。 使用我的手机开热点&#xff0c;两台电脑连接热点。 我的&#xff1a; IPv4 地址 . . . . . . . . . . . . : 192.168.92.79 子…

labview技术交流-如何判断一个数是否为质数

问题起源 如何判断一个数是否为质数&#xff0c;其实并不难&#xff0c;只要你知道质数的定义&#xff0c;按照它的定义去编写代码就可以了。但是没有思路的人可能就会一直找不到方向&#xff0c;所以我就简单介绍一下。 还有我想吐槽的点&#xff0c;labview本来就是很小众的语…

【氧化镓】β-Ga2O3肖特基势垒二极管的缺陷识别

本文是一篇关于β-Ga2O3肖特基势垒二极管在电子辐射和退火调节下缺陷识别的研究。文章首先介绍了β-Ga2O3作为一种高性能器件材料的重要性&#xff0c;然后详细描述了实验方法&#xff0c;包括样品制备、电子辐照、热退火处理以及电学特性和深能级瞬态谱&#xff08;DLTS&#…

英特尔AI训练芯片惊艳亮相:速度与性能双超H200,引领AI新浪潮

英特尔甩出全新AI训练芯片&#xff01;跑千亿大模型速度超H200&#xff0c;罕见披露AI浮点性能 大规模AI计算已经进入系统竞赛。 英特尔在年度Intel Vision大会上重磅推出新一代AI训练芯片Gaudi 3&#xff0c;正面向英伟达旗舰芯片发起挑战。会上&#xff0c;英特尔CEO基辛格挥…

html页面跳转的方法

1、加在head里面 <head> <meta http-equiv"refresh" content"1;urlhttps://ha.huatu.com/zt/hnsylkseo/?"> </head> 2、加在body里面 在body里用js <script language"javascript" type"text/javascript">…

C++感受4-HelloWorld中文版——认识编码

及时了解“编码”对编写代码的影响&#xff0c;是中国程序员越早知道越好的知识点。 一分钟了解什么叫“编码”和“解码”&#xff1b;通过实际演示&#xff0c;充分理解中文Windows下&#xff0c;C源代码编码需要注意的地方&#xff1b;通过 -finput-charsetutf8 等 g 编译配置…

数据可视化-ECharts Html项目实战(11)

在之前的文章中&#xff0c;我们学习了如何在ECharts中特殊图表的双y图以及自定义形状词云图。想了解的朋友可以查看这篇文章。同时&#xff0c;希望我的文章能帮助到你&#xff0c;如果觉得我的文章写的不错&#xff0c;请留下你宝贵的点赞&#xff0c;谢谢。 数据可视化-ECh…

【随笔】Git 高级篇 -- 纠缠不清的分支 rebase | cherry-pick(二十四)

&#x1f48c; 所属专栏&#xff1a;【Git】 &#x1f600; 作  者&#xff1a;我是夜阑的狗&#x1f436; &#x1f680; 个人简介&#xff1a;一个正在努力学技术的CV工程师&#xff0c;专注基础和实战分享 &#xff0c;欢迎咨询&#xff01; &#x1f496; 欢迎大…

基于特征的多模态生物信号信息检索与自相似矩阵:专注于自动分割

论文地址&#xff1a;Biosensors | Free Full-Text | Feature-Based Information Retrieval of Multimodal Biosignals with a Self-Similarity Matrix: Focus on Automatic Segmentation (mdpi.com) 论文源码&#xff1a;无 期刊&#xff1a;biosensors 这篇论文提出了一种基…

全国项目管理标准化技术委员会副秘书长肖杨先生受邀为第十三届中国PMO大会演讲嘉宾

全国PMO专业人士年度盛会 全国项目管理标准化技术委员会副秘书长、微薄之力&#xff08;北京&#xff09;管理咨询有限公司董事长肖杨先生受邀为PMO评论主办的2024第十三届中国PMO大会演讲嘉宾&#xff0c;演讲议题为“数字化时代下&#xff0c;由职能型组织向高度适应性组织转…

GCB Meta分析 | 土壤水分-大气反馈主导全球陆地N2O硝化的排放和反硝化的减少

原名&#xff1a;Soil moisture–atmosphere feedback dominates land N2O nitrification emissions and denitrification reduction 译名&#xff1a;土壤水分-大气反馈主导着陆地N2O硝化的排放和反硝化的减少 期刊&#xff1a;Global Change Biology 通讯作者&#xff1a…

OSCP靶场--Dibble

OSCP靶场–Dibble 考点(前端鉴权参数修改node.js代码注入 suid cp提权 ) 1.nmap扫描 ## ┌──(root㉿kali)-[~/Desktop] └─# nmap 192.168.173.110 -sV -sC -Pn --min-rate 2500 -p- Starting Nmap 7.92 ( https://nmap.org ) at 2024-04-09 06:36 EDT Nmap scan repor…

Golang | Leetcode Golang题解之第21题合并两个有序链表

题目&#xff1a; 题解&#xff1a; func mergeTwoLists(list1, list2 *ListNode) *ListNode {if list1 nil {return list2 // 注&#xff1a;如果都为空则返回空}if list2 nil {return list1}if list1.Val < list2.Val {list1.Next mergeTwoLists(list1.Next, list2)re…