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

3 vues (au cours des 30 derniers jours)
Haya Ali
Haya Ali le 1 Août 2023
Commenté : Haya Ali le 3 Août 2023
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

Réponse acceptée

Voss
Voss le 1 Août 2023
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 commentaires
Voss
Voss le 2 Août 2023
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 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 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 le 3 Août 2023
Maybe theres a problem with my MATLAB. Thanks for the quick response.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by