How are coordinates in plot(graph(M)) generated?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tobias Johansson
il 21 Dic 2015
Commentato: Tobias Johansson
il 28 Dic 2015
Given an undirected unweighted adjacency matrix M consisting of only ones and zeros, Matlab can generate a visual graph representation using:
p = plot(graph(M))
Depending on what the exact configuration of M is, the coordinates of p will be different. I have two questions:
- What is the default method used by Matlab for generating coordinates in the plot p?
- Are there alternatives to the default method, for example, if one would like to base location of nodes in the plot on some centrality measure of choice?
0 Commenti
Risposta accettata
Christine Tobler
il 21 Dic 2015
There are different layout methods for plotting a graph, which you can call as follows:
plot(graph(M), 'layout', LAY);
with LAY one of 'force', 'subspace', 'layered' and 'circle'. By default, one of the first three is chosen based on the structure and size of the input graph.
Alternative, you can compute the x- and y-coordinates of each node yourself, and use the command
plot(graph(M), 'XData', x, 'YData', y);
I'm not aware of methods to plot a graph based on a centrality measure. Do you have more information about this?
3 Commenti
Christine Tobler
il 22 Dic 2015
Currently, the choice between layouts is:
- 'subspace' for graphs with more than 100 nodes
- 'layered' for graphs with <= 100 nodes that have no cycles
- 'force' for graphs with <= 100 nodes that have cycles
For the second point, MATLAB does not provide such a layout method, but here is some code that generates something similar:
% Generate graph with few very central nodes:
M = sprandn(80, 80, 0.01);
M(1:5, :) = sprandn(5, 80, 0.3);
g = graph(M, 'upper');
h = plot(g);
% Layout plot based on degree-centrality:
d = degree(g);
r = max(d) + 2 - d;
phi = linspace(0, 360, numnodes(g)+1)';
phis = phi;
phis(end) = [];
h.XData = r.*cosd(phis);
h.YData = r.*sind(phis);
for ii=2:max(d)+2
if any(r == ii)
hold on;
plot(ii*cosd(phi), ii*sind(phi), 'Color', [0.8 0.8 0.8]);
end
end
uistack(h, 'top')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!