フィルターのクリア

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

2 ビュー (過去 30 日間)
Tobias Johansson
Tobias Johansson 2015 年 12 月 21 日
コメント済み: Tobias Johansson 2015 年 12 月 28 日
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?

採用された回答

Christine Tobler
Christine Tobler 2015 年 12 月 21 日
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 件のコメント
Christine Tobler
Christine Tobler 2015 年 12 月 22 日
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 2015 年 12 月 28 日
Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by