forked from joelibaceta/hacktoberfest-training-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
65 lines (43 loc) · 1.35 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
import csv
from matplotlib import pyplot as plt, cm
import numpy as np
from random import shuffle
data = [{}, {}, {}, {}, {}]
def export_pie_char(i):
slices = [1,2,3] * 4 + [20, 25, 30] * 2
shuffle(slices)
cmap = plt.cm.tab20c
colors = cmap(np.linspace(0., 1., len(slices)))
labels = list(data[i].keys())
sizes = list(data[i].values())
plt.pie(sizes, labels=labels, colors=colors)
plt.axis('equal')
plt.savefig('output/pie_' + str(i) + '.png')
plt.clf()
def export_age_bar():
dict2 = {}
for key in sorted(data[4].keys()):
if not key in dict2:
dict2[key] = data[4][key]
objects = list(dict2.keys())
values = dict2.values()
plt.bar(objects, values)
plt.savefig('output/bar.png')
plt.clf()
with open('survey.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
for x in range(0, 5):
value = row[x].strip()
if (data[x] == None):
data[x] = {}
if (data[x].get(value) == None):
data[x][value] = 1
else:
data[x][value] = data[x][value] + 1
export_pie_char(0) # Languages
export_pie_char(1) # OSs
export_pie_char(2) # IDEs
export_pie_char(3) # Countries
export_age_bar()