-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeld_bank.py
53 lines (40 loc) · 1.25 KB
/
geld_bank.py
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
import benfords_law
import matplotlib.pyplot as plt
def calculate_new_money(a):
numbers = [1]
for i in range(1, a):
new_n = numbers[i-1] * 1.2
numbers.append(new_n)
with open("data/geld_bank.csv", "w") as f:
for n in numbers:
f.write(str(format(n, 'f')) + "\n")
def plot(a, show_benford=False):
benfords_law_dist = [30.1, 17.6, 12.5, 9.7, 7.9, 6.7, 5.8, 5.1, 4.6]
percentage, _, _ = benfords_law.calculate("geld_bank", 0, 0, a)
percentage.pop(0)
y = percentage
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
plt.clf()
plt.bar(x, y, width=.8)
plt.xlabel('Ziffer')
plt.xticks(x)
plt.ylabel('Prozent')
plt.title("Geld Bank / " + str(a) + " Tage")
if show_benford: plt.plot(x, benfords_law_dist, "r--")
plt.pause(.0000000000001)
if __name__ == "__main__":
start = 20
plot(start)
input("start animation: ")
for a in range(start, 201):
plot(a)
benfords_law_dist = [30.1, 17.6, 12.5, 9.7, 7.9, 6.7, 5.8, 5.1, 4.6]
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
input("show benfords law: ")
plt.plot(x, benfords_law_dist, "r--")
plt.pause(.0001)
input("1000: ")
for a in range(200, 1001, 10):
plot(a, True)
input("close: ")
plt.close()