-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot-benford-graph.py
More file actions
40 lines (38 loc) · 1.06 KB
/
plot-benford-graph.py
File metadata and controls
40 lines (38 loc) · 1.06 KB
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
from cProfile import label
import numpy as np
import matplotlib.pyplot as plt
records = []
file = open('data.txt', 'r')
lines = file.readlines()
for line in lines:
records.append(int(line))
print(records)
count1,count2,count3,count4,count5,count6,count7,count8,count9 = 0,0,0,0,0,0,0,0,0
for num in records:
if str(num)[:1]=='1':
count1=count1+1
if str(num)[:1]=='2':
count2=count2+1
if str(num)[:1]=='3':
count3=count3+1
if str(num)[:1]=='4':
count4=count4+1
if str(num)[:1]=='5':
count5=count5+1
if str(num)[:1]=='6':
count6=count6+1
if str(num)[:1]=='7':
count7=count7+1
if str(num)[:1]=='8':
count8=count8+1
if str(num)[:1]=='9':
count9=count9+1
counted_list = [count1,count2,count3,count4,count5,count6,count7,count8,count9]
print(counted_list)
x_axis = [1,2,3,4,5,6,7,8,9]
y_axis = counted_list
fig, ax = plt.subplots()
ax.set_xticks(x_axis, labels=['1','2','3','4','5','6','7','8','9'])
ax.set_title('Count of Leading Digits')
ax.bar(x_axis, y_axis)
plt.show()