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
댓글 수: 0
채택된 답변
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
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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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));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!