-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharts.py
32 lines (27 loc) · 1.01 KB
/
charts.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
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('agg')
def bar_chart(data):
fig, ax = plt.subplots()
ax.bar([r["university_location_code"] for r in data], [r["count"] for r in data])
ax.set_xticks([r["university_location_code"] for r in data])
ax.set_xlabel("University Location")
ax.set_ylabel("Count")
ax.set_title("University Rankings")
return fig
def table(data):
ranks = [d['position'] for d in data]
universities = [d['university'] for d in data]
fig, ax = plt.subplots()
ax.set_axis_off()
table_data = [[rank, university_name] for rank, university_name in zip(ranks, universities)]
table = ax.table(cellText=table_data,
colLabels=['Rank', 'University Name'],
loc='center',
cellLoc="center",
colWidths=[0.09, 1.1],
colColours=["#9bc4e2"] * 2)
table.auto_set_font_size(False)
table.set_fontsize(14)
table.scale(1, 1.5)
return fig