-
Notifications
You must be signed in to change notification settings - Fork 11
/
3_chart_csv_starter.py
58 lines (35 loc) · 1.22 KB
/
3_chart_csv_starter.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
import csv
import collections
import matplotlib.pyplot as plt
import numpy
def main():
csvfile = open('data/childhood_deaths.csv', 'rU')
reader = csv.DictReader(csvfile)
for row in reader:
if row['Country Name'] == 'Finland':
finland_data = extractData(row)
elif row['Country Name'] == 'El Salvador':
el_salvador_data = extractData(row)
elif row['Country Name'] == 'United States':
usa_data = extractData(row)
# erase this after extractData() is complete
finland_data = [70, 35, 30, 20, 40]
el_salvador_data = [70, 35, 30, 20, 40]
usa_data = [70, 35, 30, 20, 40]
fig = plt.figure()
ax = fig.add_subplot(111)
finland_index = numpy.arange(len(finland_data))
width = 0.35
rects_finland = ax.bar(finland_index, finland_data, width, color="r")
rects_el_salvador = ax.bar(finland_index+width, el_salvador_data, width, color="g")
rects_usa = ax.bar(finland_index+2*width, usa_data, width, color="y")
ax.legend( (rects_finland[0], rects_el_salvador[0], rects_usa[0]), ('Finland', 'El Salvador', 'United States') )
plt.show()
return
def extractData(row):
data = {}
for key, value in row.iteritems():
# Fill this in
data[key] = "FOO"
return collections.OrderedDict(sorted(data.items()))
main()