Intro to MatPlotLib with wikipedia biography metadata
[matplotlib-cdsw] / hist2d.py
1 """Make a 2D histogram ("heat map") of the male and female articles by birth year and first edit date"""
2 import wikibios
3 from datetime import datetime
4 from matplotlib import pyplot, dates
5
6 figure = pyplot.figure()
7
8 min_firstedit = min(dates.date2num(wikibios.columns['firstedit']))
9 max_firstedit = max(dates.date2num(wikibios.columns['firstedit']))
10
11 firstedits_male = dates.date2num(wikibios.columns_male['firstedit'])
12 birth_years_male = wikibios.columns_male['birth_year']
13
14 axes1 = figure.add_subplot(1,2,1)
15 h1 = axes1.hist2d(firstedits_male, birth_years_male, range=[[min_firstedit, max_firstedit], [1750, 2014]], bins=50)
16 figure.colorbar(h1[3])
17 axes1.xaxis.set_major_formatter(dates.AutoDateFormatter(dates.AutoDateLocator()))
18
19 firstedits_female = dates.date2num(wikibios.columns_female['firstedit'])
20 birth_years_female = wikibios.columns_female['birth_year']
21
22 axes2 = figure.add_subplot(1,2,2)
23 h2 = axes2.hist2d(firstedits_female, birth_years_female, range=[[min_firstedit, max_firstedit], [1750, 2014]], bins=50)
24 figure.colorbar(h2[3])
25 axes2.xaxis.set_major_formatter(dates.AutoDateFormatter(dates.AutoDateLocator()))
26
27 figure.savefig('hist2d.png')

Benjamin Mako Hill || Want to submit a patch?