-
Notifications
You must be signed in to change notification settings - Fork 76
/
drawCircGraph.m
executable file
·53 lines (43 loc) · 1.26 KB
/
drawCircGraph.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Draw a circular representation of a graph with the nodes ordered by degree
% Strategy: position vertices in a regular n-polygon
%
% INPUTs: adj, nxn - adjacency matrix
% OUTPUTs: plot
%
% Other routines used: degrees.m
% Last updated: Nov 29 2012
function [] = drawCircGraph(adj)
n = size(adj, 1); % number of nodes
[~, Y] = sort(degrees(adj)); % Y - sorted nodal indices
angl = 2 * pi / n; % rotation angle
for k = 1:n
x(Y(k)) = real(exp(angl * (k - 1) * i));
y(Y(k)) = imag(exp(angl * (k - 1) * i));
end
% regulate the font size with respect to graph size
if n <= 50;
fontsize = 10;
elseif n > 50 && n <= 150
fontsize = 8;
else
fontsize = 6;
end
for k = 1:n
plot(x(k), y(k), 'k.')
text(1.15 * x(k), 1.15 * y(k), strcat('v', num2str(k)), "fontsize", fontsize);
hold off; hold on;
end
edges = find(adj > 0);
set(gcf, 'Color', [1, 1, 1])
for e = 1:length(edges)
[ii, jj] = ind2sub([n, n], edges(e));
line([x(ii) x(jj)], [y(ii) y(jj)], 'Color', 'k');
hold off; hold on;
end
axis([-1.15 1.15 -1.15 1.15])
axis square
axis off
%!demo
%! el = preferentialAttachment(60, 1);
%! adj = edgeL2adj(el);
%! drawCircGraph(adj)