-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhist.py
59 lines (44 loc) · 1.52 KB
/
hist.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
54
55
56
57
58
59
# -*- coding: utf-8 -*-
import csv
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import numpy as np
#fldName = 'greedyWalkPathLenght'
#inFileName = 'commonFeatures_erdesh.csv'
inFileName = 'commonFeatures_sp_erdesh.csv'
fldName = 'sp'
outFileName = fldName + "_distr.csv"
numbers=[]
#with open('commonFeatures_erdesh.csv', 'rb') as csvfile:
with open(inFileName) as csvfile:
#spreader = csv.reader(csvfile, delimiter=';', quotechar='|')
reader = csv.DictReader(csvfile, delimiter=';', quotechar='|');
for row in reader:
numbers.append(int( row[fldName]))
print len(numbers)
print numbers[0:20]
myMaxNumber = np.amax(numbers)
print "myMaxNumber is %i" % myMaxNumber
#bins = array.array('i',(i for i in range(0,myMaxNumber)))
bins = [i for i in xrange(myMaxNumber+1)]
n, bins, patches = plt.hist(numbers, bins, normed=1, facecolor='green', alpha=0.5)
print n
with open(outFileName, 'wb') as csvWriterFile:
fieldnames = ['lenght', 'probability']
writer = csv.DictWriter(csvWriterFile, fieldnames=fieldnames,delimiter=';')
writer.writeheader()
for x,y in zip(bins, n):
writer.writerow({'lenght': x, 'probability': str(y).replace(".",",")})
#print "x: %i y: %.5f" % (x,y)
# add a 'best fit' line
#mu=5;
#sigma = 3;
#y = mlab.normpdf(bins, mu, sigma)
#plt.plot(bins, y, 'r--')
#plt.xlabel("Smart")
plt.xlabel("Lenght")
plt.ylabel('Probability')
plt.title(r'Histogram of IQ: $\mu=100$, $\sigma=15$')
# Tweak spacing to prevent clipping of ylabel
plt.subplots_adjust(left=0.15)
#plt.show()