In [1]:
%matplotlib qt4
from __future__ import division

from models import tools, optimize, models, filters
from models.tests import PerformanceTest

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

In [2]:
data = tools.load_data(offset=1500000, limit=1000000)
print len(data)


787987

In [11]:
options = [0, 2, 4, 6]
data_with_options = []
for options_count in options:
    d = data[data['number_of_options'] == options_count]
    data_with_options += [len(d[d['is_correct'] == 0]) / len(d[d['is_correct'] == 1])]

In [69]:
ind = np.arange(len(options))    # the x locations for the groups
width = 0.50       # the width of the bars: can also be len(x) sequence

p1 = plt.bar(ind, [(1 - p) * 100 for p in data_with_options],   width, color='#7FFF24')
p2 = plt.bar(ind, [p * 100 for p in data_with_options], width, color='#ff512e',
             bottom=[(1 - p) * 100 for p in data_with_options])

plt.ylabel('%')
plt.xticks(ind+width/2., ('open', '2 options', '4 options', '6 options'))
plt.yticks(np.arange(0, 101, 10))
plt.legend((p1[0], p2[0]), ('correct', 'incorrect'), loc=4)

def autolabel(rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x()+rect.get_width()/2., height - 5, r'{} %'.format(round(height, 1)),
                 ha='center', va='bottom')
        
autolabel(p1)

plt.show()

In [ ]: