1
+ # Filename: SIR_Final_Rank_Figure.py
2
+ # Description: Optional module to plot the
3
+ # results of SIR method
4
+ # Authors: Papathanasiou, J. & Ploskas, N.
5
+
6
+ import matplotlib .pyplot as plt
7
+ from graphviz import Digraph
8
+ from numpy import *
9
+
10
+ # Plot final rank figure
11
+ def graph (flows , b ):
12
+ """ flows is the matrix with the flows, and b
13
+ is a string describing the flow
14
+ """
15
+ s = Digraph ('Actions' , node_attr = {'shape' :
16
+ 'plaintext' })
17
+ s .body .extend (['rankdir = LR' ])
18
+ x = sort (flows )
19
+ y = argsort (flows )
20
+ l = []
21
+ for i in y :
22
+ s .node ('action' + str (i ), '''<
23
+ <TABLE BORDER="0" CELLBORDER="1"
24
+ CELLSPACING="0" CELLPADDING="4">
25
+ <TR>
26
+ <TD COLSPAN="2" bgcolor="grey" >Action
27
+ ''' + str (y [i ] + 1 ) + '''</TD>
28
+ </TR>
29
+ <TR>
30
+ <TD>''' + b + '''</TD>
31
+ <TD>''' + str (x [i ]) + '''</TD>
32
+ </TR>
33
+ </TABLE>>''' )
34
+ k = []
35
+ for q in range (len (flows ) - 1 ):
36
+ k .append (['action' + str (q + 1 ), 'action'
37
+ + str (q )])
38
+ print (k )
39
+ s .edges (k )
40
+ s .view ()
41
+
42
+ # Plot final rank
43
+ def plot (a , b ):
44
+ """ a is the matrix with the flows, and b
45
+ is a string describing the method
46
+ """
47
+ flows = a
48
+ yaxes_list = [0.2 ] * size (flows , 0 )
49
+ plt .plot (yaxes_list , flows , 'ro' )
50
+ frame1 = plt .gca ()
51
+ frame1 .axes .get_xaxis ().set_visible (False )
52
+ plt .axis ([0 , 0.7 , min (flows ) - 0.05 ,
53
+ max (flows ) + 0.05 ])
54
+ plt .title (b + " results" )
55
+ plt .ylabel ("Flows" )
56
+ plt .legend ()
57
+ plt .grid (True )
58
+ z1 = []
59
+ for i in range (size (flows , 0 )):
60
+ z1 .append (' (Action ' + str (i + 1 ) + ')' )
61
+ z = [str (a ) + b for a , b in zip (flows , z1 )]
62
+ for X , Y , Z in zip (yaxes_list , flows , z ):
63
+ plt .annotate ('{}' .format (Z ), xy = (X , Y ),
64
+ xytext = (10 , - 4 ), ha = 'left' ,
65
+ textcoords = 'offset points' )
66
+ plt .show ()
0 commit comments