1 """Plot the fraction of articles that are female, by birth year and first edit date."""
3 from matplotlib import pyplot
4 from operator import itemgetter
6 figure = pyplot.figure()
8 rows_by_birth_year = sorted(wikibios.rows, key=itemgetter('birth_year'))
9 birth_year_medians = []
10 fraction_female_by_birth_year = []
13 while i + N <= len(rows_by_birth_year):
14 chunk = rows_by_birth_year[i:i+N]
17 birth_year_medians.append(chunk[N / 2]['birth_year'])
21 if row['gender'] == 'female':
22 count_female = count_female + 1
23 fraction_female = count_female / N
24 fraction_female_by_birth_year.append(fraction_female)
26 axes1 = figure.add_subplot(2, 1, 1)
27 axes1.plot(birth_year_medians, fraction_female_by_birth_year)
28 axes1.set_xlabel('Birth Year')
29 axes1.set_ylabel('Fraction Female')
31 rows_by_firstedit = sorted(wikibios.rows, key=itemgetter('firstedit'))
32 fraction_female_by_firstedit = []
33 firstedit_medians = []
35 while i + N <= len(rows_by_birth_year):
36 chunk = rows_by_firstedit[i:i+N]
39 firstedit_medians.append(chunk[N / 2]['firstedit'])
43 if row['gender'] == 'female':
44 count_female = count_female + 1
45 fraction_female = count_female / N
46 fraction_female_by_firstedit.append(fraction_female)
48 axes2 = figure.add_subplot(2, 1, 2)
49 axes2.plot(firstedit_medians, fraction_female_by_firstedit)
50 axes2.set_xlabel('Article Year')
51 axes2.set_ylabel('Fraction Female')
53 figure.savefig('fractions.pdf')