55__author__ = "Yannick Copin <[email protected] >" 66__version__ = "Time-stamp: <10/02/2010 16:49 [email protected] >" 77
8- import numpy as N
8+ import numpy as np
99
1010def sankey (ax ,
1111 outputs = [100. ], outlabels = None ,
@@ -30,19 +30,19 @@ def sankey(ax,
3030 import matplotlib .patches as mpatches
3131 from matplotlib .path import Path
3232
33- outs = N .absolute (outputs )
34- outsigns = N .sign (outputs )
33+ outs = np .absolute (outputs )
34+ outsigns = np .sign (outputs )
3535 outsigns [- 1 ] = 0 # Last output
3636
37- ins = N .absolute (inputs )
38- insigns = N .sign (inputs )
37+ ins = np .absolute (inputs )
38+ insigns = np .sign (inputs )
3939 insigns [0 ] = 0 # First input
4040
4141 assert sum (outs )== 100 , "Outputs don't sum up to 100%"
4242 assert sum (ins )== 100 , "Inputs don't sum up to 100%"
4343
4444 def add_output (path , loss , sign = 1 ):
45- h = (loss / 2 + w )* N .tan (outangle / 180. * N .pi ) # Arrow tip height
45+ h = (loss / 2 + w )* np .tan (outangle / 180. * np .pi ) # Arrow tip height
4646 move ,(x ,y ) = path [- 1 ] # Use last point as reference
4747 if sign == 0 : # Final loss (horizontal)
4848 path .extend ([(Path .LINETO ,[x + dx ,y ]),
@@ -64,7 +64,7 @@ def add_output(path, loss, sign=1):
6464 outtips .append ((sign ,path [- 5 ][1 ]))
6565
6666 def add_input (path , gain , sign = 1 ):
67- h = (gain / 2 )* N .tan (inangle / 180. * N .pi ) # Dip depth
67+ h = (gain / 2 )* np .tan (inangle / 180. * np .pi ) # Dip depth
6868 move ,(x ,y ) = path [- 1 ] # Use last point as reference
6969 if sign == 0 : # First gain (horizontal)
7070 path .extend ([(Path .LINETO ,[x - dx ,y ]),
@@ -109,7 +109,7 @@ def revert(path):
109109 path = urpath + revert (lrpath ) + llpath + revert (ulpath )
110110
111111 codes ,verts = zip (* path )
112- verts = N .array (verts )
112+ verts = np .array (verts )
113113
114114 # Path patch
115115 path = Path (verts ,codes )
@@ -168,15 +168,15 @@ def put_labels(labels,positions,output=True):
168168
169169if __name__ == '__main__' :
170170
171- import matplotlib .pyplot as P
171+ import matplotlib .pyplot as plt
172172
173173 outputs = [10. ,- 20. ,5. ,15. ,- 10. ,40. ]
174174 outlabels = ['First' ,'Second' ,'Third' ,'Fourth' ,'Fifth' ,'Hurray!' ]
175175 outlabels = [ s + '\n %d%%' % abs (l ) for l ,s in zip (outputs ,outlabels ) ]
176176
177177 inputs = [60. ,- 25. ,15. ]
178178
179- fig = P .figure ()
179+ fig = plt .figure ()
180180 ax = fig .add_subplot (1 ,1 ,1 , xticks = [],yticks = [],
181181 title = "Sankey diagram"
182182 )
@@ -187,5 +187,5 @@ def put_labels(labels,positions,output=True):
187187 outtexts [1 ].set_color ('r' )
188188 outtexts [- 1 ].set_fontweight ('bold' )
189189
190- P .show ()
190+ plt .show ()
191191
0 commit comments