""" Author: Mathieu Perreault COMP364, Lecture 20 """ import matplotlib.pyplot as plt import numpy as np # Parameters width = 0.35 menlabel = [] menvalues = [] for line in open('../files/men.txt'): label, value = line.strip().split(',') value = int(value) menlabel.append(label) menvalues.append(value) menbars = [0.1*v for v in menvalues] womenlabel = [] womenvalues = [] for line in open('../files/women.txt'): label, value = line.strip().split(',') value = int(value) womenlabel.append(label) womenvalues.append(value) womenbars = [0.1*v for v in womenvalues] plt.figure() ind = np.arange(len(menlabel)) plt.title('Score by group and gender') plt.ylabel('Scores') plt.bar(ind, menvalues, color='r', width=width,yerr=menbars) plt.bar(ind, womenvalues, bottom=menvalues, color='y', width=width,yerr=womenbars) plt.xticks(ind+width/2., menlabel) labels = ['Men', 'Women'] plt.legend(labels) plt.show()