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

3 次查看(过去 30 天)
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;
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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3";"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));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by