-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraphics_parse.py
177 lines (127 loc) · 5.33 KB
/
graphics_parse.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import matplotlib.pyplot as plt
import json
import numpy as np
import random
def piePlot(data, title, path):
plt.rcParams.update({'font.size': 13})
fig = plt.figure(figsize = (15, 10))
explode = [0, 0.5] * 4
#print(data)
pie = plt.pie(data.values(), labels=data.keys(), autopct='%1.1f%%',
wedgeprops= {"edgecolor":"white",
'linewidth': 3,
'antialiased': True})
hatches = ['o' if value==min(data) else 'O' if value==max(data) else '' for value in data]
# for i in range(len(pie[0])):
# pie[0][i].set(hatch = hatches[i], fill=False)
plt.title(title, fontsize=30)
plt.axis('equal')
plt.savefig(path)
plt.show()
def barPlot(data, title, xAxis, yAxis, path):
fig = plt.figure(figsize = (20, 10))
plt.bar(data.keys(), data.values(), color ='maroon', width = 0.4)
plt.xlabel(xAxis)
plt.ylabel(yAxis)
plt.title(title, fontsize=20)
plt.savefig(path)
plt.show()
def splitString(string):
if '["' in string:
allAuthors = string.split('["')
allAuthors = allAuthors[1].split('"]')
allAuthors = allAuthors[0].split('", "')
else:
allAuthors = string.split("['")
allAuthors = allAuthors[1].split("']")
allAuthors = allAuthors[0].split("', '")
return allAuthors
def checkExistance(dict, key):
if key in dict:
dict[key] += 1
else:
dict[key] = 1
def plotAreas(papers):
areaCounters = {}
areaCounters["Others: \n-Quantitative Biology, \n-Electrical Eng. and Systems Science, \n-Quantitative Finance, \n-Economics"] = 0
for paper in papers:
for area in paper["tags"].keys():
if area not in areaCounters.keys():
areaCounters[area] = 1
else:
areaCounters[area] += 1
for k in areaCounters.keys():
if areaCounters[k] < 1000:
areaCounters["Others: \n-Quantitative Biology, \n-Electrical Eng. and Systems Science, \n-Quantitative Finance, \n-Economics"] += areaCounters[k]
del areaCounters["Quantitative Biology"]
del areaCounters["Electrical Engineering and Systems Science"]
del areaCounters["Quantitative Finance"]
del areaCounters["Economics"]
piePlot(areaCounters, "Most Common Areas", "../docs/res/areas.jpg")
def plotFields(papers):
fieldCounters = {}
fieldCounters["Others"] = 0
#areaCounters["Others: \n-Quantitative Biology, \n-Electrical Eng. and Systems Science, \n-Quantitative Finance, \n-Economics"] = 0
for paper in papers:
for area in paper["tags"].keys():
for field in paper["tags"][area].keys():
if area != "Physics":
continue
if field not in fieldCounters.keys():
fieldCounters[field] = 1
else:
fieldCounters[field] += 1
delList = []
for elem in fieldCounters.keys():
if fieldCounters[elem] < 10:
fieldCounters["Others"] += fieldCounters[elem]
delList.append(elem)
print(fieldCounters)
for e in delList:
if e != "Others":
del fieldCounters[e]
print(fieldCounters)
# for k in areaCounters.keys():
# if areaCounters[k] < 1000:
# areaCounters["Others: \n-Quantitative Biology, \n-Electrical Eng. and Systems Science, \n-Quantitative Finance, \n-Economics"] += areaCounters[k]
# del areaCounters["Quantitative Biology"]
# del areaCounters["Electrical Engineering and Systems Science"]
# del areaCounters["Quantitative Finance"]
# del areaCounters["Economics"]
piePlot(fieldCounters, "Most Common Physics Field", "../docs/res/field.jpg")
def main():
with open('./data/refined_data.json', 'r') as dataset:
papers = json.loads(dataset.read())
plotFields(papers)
# areaCounters = {}
# #areaCounters["Others"] = 0
# for paper in papers:
# for area in paper["tags"].keys():
# if area not in areaCounters.keys():
# areaCounters[area] = 1
# else:
# areaCounters[area] += 1
# fig, ax = plt.subplots(figsize=(15, 10), subplot_kw=dict(aspect="equal"))
# recipe = list(areaCounters.keys())
# data = areaCounters.values()
# zipped_lists = list(zip(recipe, data))
# random.shuffle(zipped_lists)
# tuples = zip(*zipped_lists)
# recipe, data = [ list(tuple) for tuple in tuples]
# wedges, texts = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)
# bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
# kw = dict(arrowprops=dict(arrowstyle="-"),
# bbox=bbox_props, zorder=0, va="center")
# for i, p in enumerate(wedges):
# ang = (p.theta2 - p.theta1)/2. + p.theta1
# y = np.sin(np.deg2rad(ang))
# x = np.cos(np.deg2rad(ang))
# horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
# connectionstyle = "angle,angleA=0,angleB={}".format(ang)
# kw["arrowprops"].update({"connectionstyle": connectionstyle})
# ax.annotate(recipe[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.6*y),
# horizontalalignment=horizontalalignment, **kw)
# ax.set_title("Matplotlib bakery: A donut")
# plt.savefig("./plots/field.png")
if __name__ == '__main__':
main()