Filter löschen
Filter löschen

How are coordinates in plot(graph(M)) generated?

2 Ansichten (letzte 30 Tage)
Tobias Johansson
Tobias Johansson am 21 Dez. 2015
Kommentiert: Tobias Johansson am 28 Dez. 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:
  1. What is the default method used by Matlab for generating coordinates in the plot p?
  2. 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?

Akzeptierte Antwort

Christine Tobler
Christine Tobler am 21 Dez. 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 Kommentare
Christine Tobler
Christine Tobler am 22 Dez. 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')
Tobias Johansson
Tobias Johansson am 28 Dez. 2015
Thank you very much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by