-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawHists.py
57 lines (45 loc) · 1.7 KB
/
drawHists.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
#!/usr/bin/env python
import sys
from pprint import pprint
import pandas as pd
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
def showHist(filename, xlabel = "values", title = "Histogram", num_bins_ = 100, min_ = 30, max_ = None):
with open(filename, 'r') as f:
x = [int(line.rstrip('\n')) for line in f]
num_bins = num_bins_
# the histogram of the data
if max_ == None:
max_ = max(x)
if max_ < min_:
min_ = 0
n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor='green', alpha=0.5, range = (min_, max_), histtype="bar")
plt.xlabel(xlabel)
plt.ylabel('Probability')
plt.title(title)
plt.show()
def showDiscrHist(filename, xlabel = "values", title = "Histogram", num_bins_ = 100, min_ = 30, max_ = None):
with open(filename, 'r') as f:
data = [int(line.rstrip('\n')) for line in f]
data = pd.Series(data)
num_bins = num_bins_
#print data
vc = data.value_counts().sort_index()
print "pages distances:"
print vc
ax = vc.plot(kind='bar')
fig = ax.get_figure()
fig.autofmt_xdate()
fig.savefig('pageDistances.png')
def main():
if len(sys.argv) >= 4:
showHist(sys.argv[1], "Bytes", "Histogram of pages' sizes")
showHist(sys.argv[2], "Links", "Histogram of incoming links for pages", 50)
showHist(sys.argv[3], "Links", "Histogram of outgoing links for pages")
if len(sys.argv) >= 5:
showDiscrHist(sys.argv[4], "Distance in clicks", "Histogram of distances from main page", 10)
else:
print "Usage: %s sizes_file in_links_file out_links_file" % sys.argv[0]
if __name__ == '__main__':
main()