In [1]:
""" Date : 05th November 2015
    Author : Sreejith Menon
"""


Out[1]:
' Date : 05th November 2015\n    Author : Sreejith Menon\n'

In [2]:
import csv
import matplotlib.pyplot as plt
import numpy as np

In [3]:
data_dict = csv.DictReader(open("../data/giraffe_masai.csv","r"))
person_id_name = {}

In [4]:
for row in data_dict:
    search_string = "Person"
    index = row["image_contributor"].find(search_string)

    if index != -1:
        annotation_id = int(row["annotation_id"])
        contributor = row["image_contributor"].strip().split('<COMMA>')
        contributor_name = contributor[1].strip()
        person_id_name[annotation_id] = contributor_name

In [5]:
picture_counts = {}

for row in person_id_name:
    name = person_id_name[row]
    if name in picture_counts.keys():
        curr_count = picture_counts[name]
        picture_counts[name] = curr_count + 1
    else:
        picture_counts[name] = 1

In [6]:
print(picture_counts)


{"Person 'B'": 364, "Person 'C'": 90, "Person 'D'": 104, "Person 'A'": 520}

In [7]:
"""Plotting data from dictionary"""
x = []
y = []
for row in picture_counts.keys():
    y.append(picture_counts[row])
    x.append(row)
   
print(x)
print(y)


["Person 'B'", "Person 'C'", "Person 'D'", "Person 'A'"]
[364, 90, 104, 520]

In [8]:
dict_length = len(picture_counts)

X = np.arange(dict_length)

Figure = plt.figure()
Axis = Figure.add_subplot(1,1,1)
for i in range(0,dict_length):
    Axis.bar(X[i], y[i], align='center',width=0.5)

Axis.set_xticks(X)
xtickNames = Axis.set_xticklabels(x)
plt.setp(x)
plt.xticks(rotation=20)
ymax = max(y) + 1
plt.ylim(0,ymax)

plt.show()




In [ ]: