How to change the color of the connections in plot to only one color?

1 回表示 (過去 30 日間)
Haya Ali
Haya Ali 2023 年 8 月 1 日
コメント済み: Haya Ali 2023 年 8 月 3 日
I am trying to make a chord diagram using the code from here (https://www.mathworks.com/matlabcentral/fileexchange/48576-circulargraph) but i am unable to change the nodes name and the color of the lines to only one color. Can anyone please help me with this.
close all; clear all; clc;
links1= [
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0;
0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0;
0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0;
1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1;
0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0;
1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1;
0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0;
1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0;
1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1;
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1;
0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 1;
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0;
0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1;
0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0;
1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0;
0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0;
0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0;
1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0];
circularGraph(links1);
[row2,col2,v2] = find(links1); %v2 will create Nx1 matrix of all correaltion values
map = colormap(hot); %intialize colormap, change the color map scheme to one of your choice
minv = min(v2(:)); %min max to establish bounds of colormap
maxv = max(v2(:));
ncol = size(map,1);
s = round(1+(ncol-1)*(v2-minv)/(maxv-minv)); %scale indicies for conversion
rgb_image = ind2rgb(s,map); %convert scaled indicies to RGB, gives Nx1X3 matrix
defaultColorMap = reshape(rgb_image, [length(v2) 3]); %reshape into Nx3 matrix

採用された回答

Voss
Voss 2023 年 8 月 1 日
To set the node labels, you can specify them with the 'Labels' input argument to circularGraph.
To set the colormap, you can specify it with the 'Colormap' input argument to circularGraph.
close all; clear all; clc;
links1= [
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0;
0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0;
0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0;
1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1;
0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0;
1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1;
0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0;
1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0;
1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1;
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1;
0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 1;
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0;
0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1;
0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0;
1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0;
0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0;
0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0;
1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0];
N = size(links1,1);
CG = circularGraph(links1, ...
'Label',cellstr(char(64+(1:N).')), ...
'Colormap',repmat([1 0 0],N,1));
  5 件のコメント
Voss
Voss 2023 年 8 月 2 日
I don't see the duplicates.
close all; clear all; clc;
links1= [
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0;
0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0;
0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0;
1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1;
0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0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1 0 0 0 -1 0 0 0 -1 0 -1 -1 -1 0 0 0 0 0 0;];
N = size(links1,1);
A = ["D1";"D2";"D3";"D4";"D5";"D6";"D7";"D8";"D9";"P1";"P2";"P3";"P4";"V1";"V2";"V3";"V4";"V5";"V6";"V7";"V8";"V9";"V10"];
CG = circularGraph(links1, ...
'Label',cellstr(char(A)), ...
'Colormap',repmat([1 0 0],N,1));
hold on
CG1 = circularGraph(links2, ...
'Label',cellstr(char(A)), ...
'Colormap',repmat([0 1 1],N,1));
Haya Ali
Haya Ali 2023 年 8 月 3 日
Maybe theres a problem with my MATLAB. Thanks for the quick response.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by