-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotGraph.m
89 lines (84 loc) · 3.14 KB
/
PlotGraph.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
%{
***************************************************************************************
* Abstract: Plot a graph according in a customized way
* Uses: This file has been compiled using Matlab R2017b
* Author: Michael Vasquez Otazu
* Email: [email protected]
* History: V1.0 - Plot graph according to its number of nodes
********************************* START LICENSE BLOCK *********************************
* The MIT License (MIT)
* Copyright (C) 2017 Michael Vasquez Otazu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above Copyright notice and this Permission Notice shall be included in all copies
* or substantial portions of the Software.
********************************** END LICENSE BLOCK **********************************
%}
function p = PlotGraph(G, u, v)
%% GRAPH CUSTOM PLOT
p = plot(G);
if (nargin < 2)
[T,q] = minspantree(G);
elseif (nargin < 3)
if (u > 0)
T = shortestpathtree(G, u);
else
disp('Source and destination nodes must be positive');
end
else % nargin >=3
if (v > 0)
if (u ~= v )
T = shortestpathtree(G, u, v);
%T = shortestpath(G, u, v, 'Method', 'positive'); % Dijkstra
else % u == v
T = shortestpathtree(G, u);
end
else
disp('Source and destination nodes must be positive');
end
end
if (numnodes(G) <= 20)
p.EdgeLabel = G.Edges.Weight;
p.LineWidth = 1.00;
p.NodeColor = [0.500, 0.001, 0.001];
p.Marker = 'o';
p.MarkerSize = 5;
nl = p.NodeLabel;
p.NodeLabel = '';
xd = get(p, 'XData');
yd = get(p, 'YData');
text(xd, yd, nl, 'Color', [0.500, 0.001, 0.001], 'FontWeight', 'bold', ...
'FontSize',9, 'HorizontalAlignment','Left', 'VerticalAlignment','Top');
highlight(p,T,'EdgeColor','r','LineWidth',1.5);
elseif (numnodes(G) <= 40)
p.EdgeLabel = G.Edges.Weight;
p.LineWidth = 0.750;
p.NodeColor = [0.500, 0.001, 0.001];
p.Marker = 'o';
p.MarkerSize = 3;
nl = p.NodeLabel;
p.NodeLabel = '';
xd = get(p, 'XData');
yd = get(p, 'YData');
text(xd, yd, nl, 'Color', [0.500, 0.001, 0.001], 'FontWeight', 'bold', ...
'FontSize',7, 'HorizontalAlignment','Left', 'VerticalAlignment','Top');
highlight(p,T,'EdgeColor','r','LineWidth',1);
else %(numnodes(G) > 40)
p.LineWidth = 0.500;
p.NodeColor = [0.500, 0.001, 0.001];
p.Marker = 'o';
p.MarkerSize = 1;
nl = p.NodeLabel;
p.NodeLabel = '';
xd = get(p, 'XData');
yd = get(p, 'YData');
text(xd, yd, nl, 'FontWeight', 'bold', 'FontSize',8, ...
'HorizontalAlignment', 'Left', 'VerticalAlignment','Top');
highlight(p,T,'EdgeColor','r','LineWidth',0.75);
end
return