forked from ivanbrugere/matlab-networks-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotMatrixPlot.m
executable file
·105 lines (92 loc) · 2.83 KB
/
dotMatrixPlot.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%##################################################################
% Draws the matrix as a column/row sorted square dot-matrix pattern
%
% INPUTs: adj (nxn) - adjacency matrix representation of the graph
% OUTPUTs: plot
%
% Note 1: Change colors and marker types in lines 66, 73, 94 and 101
% Note 2: Easy to add/remove different node orderings to/from the plot
%
% Other routines used: degrees.m, sortNodesByMaxNeighborDegree.m,
% eigenCentrality.m, newmanEigenvectorMethod.m,
% nodeBetweennessFaster.m, newmanGirvan.m
% GB: last updated, November 25 2012
%##################################################################
function [] = dotMatrixPlot(adj)
n = size(adj,1);
%markersize=ceil(n/50); % scale for plotting purposes
markersize=3;
deg = degrees(adj);
Yd = sortNodesByMaxNeighborDegree(adj); % degree centrality
[~, Yb] = sort(nodeBetweennessFaster(adj)); % node betweenness centrality
[~,Yec] = sort(eigenCentrality(adj)); % eigen-centrality
[~,Yc] = sort(closeness(adj)); % closeness
% sort by module
modules = newmanEigenvectorMethod(adj);
% sort modules by length
mL=zeros(1,length(modules));
for i=1:length(modules); mL(i)=length(modules{i}); end
[~,Yms]=sort(mL);
% sort nodes by degree inside modules
Ym=[];
for mm=1:length(modules)
module=modules{Yms(mm)};
deg_module=deg(module);
[~,Yds]=sort(deg_module);
module_sorted=module(Yds);
for xx=1:length(module_sorted)
Ym=[Ym module_sorted(xx)];
end
end
mods = newmanGirvan(adj,4); % enter the expected number of communities
% sort modules by length
mL=zeros(1,length(mods));
for i=1:length(mods); mL(i)=length(mods{i}); end
[~,Yms]=sort(mL);
Ymb = [];
for mm=1:length(mods)
module=mods{Yms(mm)};
deg_module=deg(module);
[~,Yds]=sort(deg_module);
module_sorted=module(Yds);
for xx=1:length(module_sorted)
Ymb=[Ymb module_sorted(xx)];
end
end
set(gcf,'Color',[1 1 1])
subplot(3,2,1)
spy(adj(Yd,Yd),'k.',markersize)
title('ordered by degree','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square
subplot(3,2,2)
spy(adj(Yb,Yb),'k.',markersize)
title('ordered by betweenness','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square
subplot(3,2,3)
spy(adj(Yec,Yec),'k.',markersize)
title('ordered by eigen-centrality','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square
subplot(3,2,4)
spy(adj(Yc,Yc),'k.',markersize)
title('ordered by closeness','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square
subplot(3,2,5)
spy(adj(Ym,Ym),'k.',markersize)
title('ordered by module - eigenvector method','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square
subplot(3,2,6)
spy(adj(Ymb,Ymb),'k.',markersize)
title('ordered by module - Newman-Girvan','FontWeight','bold')
axis([0 n 0 n]);
set(gca,'YDir','normal')
axis square