-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plot_Network_Edges.m
81 lines (73 loc) · 1.99 KB
/
Plot_Network_Edges.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
function xy = Plot_Network_Edges(adjacency,type,xy,xyColors)
% Plot weighted and undirected network edegs with loops
%
% xy = Plot_Network_Edges(adjacency,type,xy,xyColors)
%
% default: type = 'undirected'; xy = 'circle'; xy_colors = Read_Colors(n);
%
% Pérez-Ortega Jesús - Dec 2019
n = length(adjacency);
switch nargin
case 3
xyColors = Read_Colors(n);
case 2
xyColors = Read_Colors(n);
xy = 'circle';
case 1
xyColors = Read_Colors(n);
xy = 'circle';
type = 'undirected';
end
% If user only enter one color
if size(xyColors,1)==1
xyColors = repmat(xyColors,n,1);
end
% If enter empty xy
lims = [];
if isempty(xy)
xy = 'circle';
end
if ischar(xy)
switch xy
case 'circle'
nodes = length(adjacency);
xy = Get_Circular_XY(nodes);
lims = [-1.5 1.5];
case 'force'
xy = Get_Force_XY(adjacency>0);
end
end
C = length(adjacency);
% Plot edges
curved = 0;
if(sum(adjacency(:)))
line_widths = zeros(C);
line_widths(adjacency>0) = rescale(adjacency(adjacency>0),0.5,5);
hold on
for a = 1:C
for b = a:C
if adjacency(a,b)
if strcmp(type,'directed')
length_arrow = 3+0.5*line_widths(a,b);
elseif strcmp(type,'undirected')
length_arrow = 0;
else
error('type should be: ''undirected'' or ''directed''')
end
edgeColor = mean([xyColors(a,:);xyColors(b,:)]);
Plot_Edge(xy(a,:),xy(b,:),curved,length_arrow,line_widths(a,b),...
edgeColor);
end
end
end
end
axis off
%set(gca,'xtick',[],'ytick',[],'xcolor',[1 1 1],'ycolor',[1 1 1])
if lims
xlim(lims)
ylim(lims)
% else
% xlim([min(xy(:,1)) max(xy(:,1))])
% ylim([min(xy(:,2)) max(xy(:,2))])
end
pbaspect([1 1 1])