Skip to content

Commit 8599f7c

Browse files
author
AEL-H
committed
added format strings for the plot titles, display insurers and reinsurers side by side in sync
1 parent 0c8e4af commit 8599f7c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

visualisation.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def __init__(self, data):
2929
self.data = data
3030
self.fig, self.ax = plt.subplots()
3131
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,
3333
init_func=self.setup_plot)
3434

3535
def setup_plot(self):
3636
"""Initial drawing of the plots."""
3737
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%%')
3939
return self.pie,
4040

4141
def data_stream(self):
@@ -52,15 +52,18 @@ def update(self, i):
5252
self.ax.clear()
5353
self.ax.axis('equal')
5454
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)))
5757
return self.pie,
5858

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)
6161

6262
def show(self):
6363
plt.show()
6464

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

Comments
 (0)