/
plot.py
80 lines (64 loc) · 2.25 KB
/
plot.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
from __future__ import with_statement
import numpy as np
import matplotlib.pyplot as plt
import cPickle
import sys
from correlation import correlation
if len(sys.argv) < 3:
print "Usage: " + sys.argv[0] + " <real pickle file> <Synthetic pickle file 2>"
sys.exit()
with open(sys.argv[1]) as input:
beginDict1 = cPickle.load(input)
popularity1 = cPickle.load(input)
with open(sys.argv[2]) as input:
beginDict2 = cPickle.load(input)
popularity2 = cPickle.load(input)
for axis in popularity1:
mergeDict = {}
for v in popularity1[axis]:
prop1 = popularity1[axis][v]
prop2 = popularity2[axis].get(v, 0)
mergeDict[v] = (prop1, prop2)
for v in popularity2[axis]:
if v not in mergeDict:
prop2 = popularity2[axis][v]
mergeDict[v] = (0, prop2)
v_list = []
prop1_list = []
prop2_list = []
for v in sorted(mergeDict.keys()):
v_list.append(v)
prop1_list.append(mergeDict[v][0])
prop2_list.append(mergeDict[v][1])
N = len(prop1_list)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, prop1_list, width, facecolor='none', hatch='//', label='Real')
rects2 = ax.bar(ind+width, prop2_list, width, facecolor='none', hatch='\\\\', label='Synthetic')
# add some
ax.set_ylabel('Probability')
ax.set_xlabel(axis.upper())
#ax.set_title('Popularity of ' + axis)
ax.set_xticks(ind+width)
xtick_lst = []
for v in v_list:
if v % 2 == 0:
xtick_lst.append(v)
else:
xtick_lst.append("")
ax.set_xticklabels(xtick_lst)
ax.axis(ymin=0, ymax=1)
ax.text(N/2 - 1, 0.9, "correlation: %0.3f"%correlation(prop1_list, prop2_list), horizontalalignment='center')
#ax.legend( (rects1[0], rects2[0]), ('Original', 'Generated') )
ax.legend()
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%0.2f'%height, ha='center', va='bottom')
#autolabel(rects1)
#autolabel(rects2)
plt.savefig(axis+".eps")