@@ -29,13 +29,13 @@ def __init__(self, data):
29
29
self .data = data
30
30
self .fig , self .ax = plt .subplots ()
31
31
self .stream = self .data_stream ()
32
- self .ani = animation .FuncAnimation (self .fig , self .update , interval = 40 ,
32
+ self .ani = animation .FuncAnimation (self .fig , self .update , repeat = False , interval = 40 ,
33
33
init_func = self .setup_plot )
34
34
35
35
def setup_plot (self ):
36
36
"""Initial drawing of the plots."""
37
37
casharr ,idarr = next (self .stream )
38
- self .pie = self .ax .pie (casharr , labels = idarr )
38
+ self .pie = self .ax .pie (casharr , labels = idarr , autopct = '%1.0f%%' )
39
39
return self .pie ,
40
40
41
41
def data_stream (self ):
@@ -52,15 +52,18 @@ def update(self, i):
52
52
self .ax .clear ()
53
53
self .ax .axis ('equal' )
54
54
casharr ,idarr = next (self .stream )
55
- self .pie = self .ax .pie (casharr , labels = idarr )
56
- self .ax .set_title ("Timestep : " + str ( i ))
55
+ self .pie = self .ax .pie (casharr , labels = idarr , autopct = '%1.0f%%' )
56
+ self .ax .set_title ("Timestep : {:,.0f} | Total cash : {:,.0f}" . format ( i , sum ( casharr ) ))
57
57
return self .pie ,
58
58
59
- def save (self ):
60
- self .ani .save ('line.mp4' , writer = 'ffmpeg' , dpi = 80 )
59
+ def save (self , filename ):
60
+ self .ani .save (filename , writer = 'ffmpeg' , dpi = 80 )
61
61
62
62
def show (self ):
63
63
plt .show ()
64
64
65
- anim = InsuranceFirmAnimation (first_run_insurance )
66
- anim .show ()
65
+ anim1 = InsuranceFirmAnimation (first_run_insurance )
66
+ anim2 = InsuranceFirmAnimation (first_run_reinsurance )
67
+ #anim1.save("insurance.mp4")
68
+ #anim2.save("reinsurance.mp4")
69
+ plt .show ()
0 commit comments