-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopularity_plot.py
More file actions
44 lines (37 loc) · 816 Bytes
/
popularity_plot.py
File metadata and controls
44 lines (37 loc) · 816 Bytes
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
__author__ = 'Lo'
from matplotlib import pyplot as plt
x = list()
y = list()
rerank = 1
pre_rank = 1
pre_frequency = None
'''
popularity_rank file example:
1 5000
2 4840
3 4820
4 4315
5 4315
6 3788
7 3715
8 3396
...
...
'''
with open('popularity_rank', 'rb') as INPUT:
for line in INPUT.readlines():
rank, frequency = line.split()
# correct the same frequency might have different ranks
if frequency == pre_frequency:
rerank = pre_rank
else:
rerank = rank
pre_frequency = frequency
print rerank, frequency
x.append(rerank)
y.append(frequency)
pre_rank = rerank
plt.loglog(x, y, basex=10, basey=10) # log-log plot
plt.title('Popularity distribution')
#plt.plot(x, y) # normal x-y plot
plt.show()