How can I plot a multilayer graph (2 layer) starting from adjacency matrices?
17 ビュー (過去 30 日間)
古いコメントを表示
I need to plot a multilayer graph starting from adjacency matrices, like the one shown in the figure.
I have 3 adjacency matrices:
- A_gas (7x7 double): graph with nodes in red;
- A_power (24x24 double): graph with nodes in blue;
- A_interlayer (7x24 double): represents the connections between nodes in red and those in blue.
1 件のコメント
Ive J
2023 年 4 月 7 日
maybe something like this?
s1 = [ 3 3 1 4 10 8 4 5 6 8];
t1 = [6 10 10 10 11 11 8 8 11 9];
s2 = [1 1 1 1 1 2 2 7 7 9];
t2 = [2 3 4 5 7 6 7 5 9 6 ];
G1 = digraph(s1, t1);
G2 = digraph(s2, t2);
hold on
ax1 = plot(G1);
ax2 = plot(G2);
採用された回答
Christine Tobler
2023 年 4 月 11 日
Here's an example of how to do this (using just some random data, since I don't have the matrices you mention above).
% Choose some random data for the adjacency matrices
A_gas = rand(7, 7) < 0.05;
A_interlayer = rand(7, 24) < 0.05;
A_power = rand(24, 24) < 0.05;
% Give names to each node, so that they are unique for both blue and red
% nodes
namesBlue = (1:24)+" blue";
namesRed = [11 12 14 16 19 20 24]+" red";
% Combine the adjacency matrices to apply to a larger graph containing all
% nodes
A = [A_power, zeros(24, 7); A_interlayer, A_gas];
g = digraph(A, [namesBlue, namesRed]);
% Plot and recolor all red nodes
p = plot(g);
highlight(p, 25:31, NodeColor='red')
p.NodeLabel = string([1:24 11 12 14 16 19 20 24]);
You could also make this a 3D plot by setting the ZData property of variable p so that all red nodes have a different height than the blue nodes do.
0 件のコメント
その他の回答 (1 件)
Vanshika Vaishnav
2023 年 4 月 11 日
You can represent the graph with this adjacency matrix:
0 1 2
1 0 3
2 3 0
To construct the graph in MATLAB, input:
A = [0 1 2; 1 0 3; 2 3 0];
node_names = {'A','B','C'};
G = graph(A,node_names)
G =
graph with properties:
Edges: [3×2 table]
Nodes: [3×1 table]
You can plot the directed graph as described in the following documentation in "Creating Graphs">>"Adjacency Matrix".
Also, you can code this way:
s1 = [ 3 3 1 4 10 8 4 5 6 8];
t1 = [6 10 10 10 11 11 8 8 11 9];
s2 = [1 1 1 1 1 2 2 7 7 9];
t2 = [2 3 4 5 7 6 7 5 9 6 ];
G1 = digraph(s1, t1);
G2 = digraph(s2, t2);
hold on
ax1 = plot(G1);
ax2 = plot(G2);
for more information refer this below documentation:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!