#!/usr/bin/env python
from matplotlib import pyplot
from matplotlib import ticker
from matplotlib import numpy
# This generates a bar graph showing birthdays per month.
# Data is from the National Center for Health Statistics, 1995-2002.
# For simplicity, I have rounded it here.
#
# http://abcnews.go.com/Health/Science/story?id=990641
#
# This file was written by Douglas Perkins.
data = [
("January", 2582009),
("February", 2409565),
("March", 2645413),
("April", 2537816),
("May", 2673858),
("June", 2629368),
("July", 2788695),
("August", 2813582),
("September", 2740831),
("October", 2694594),
("November", 2532156),
("December", 2631533),
]
months = [d[0] for d in data]
births = [d[1] for d in data]
# A formatter to display comma-separated numbers on the y axis.
def comma_func(y, pos):
s = '{:0,d}'.format(int(y))
return s
comma_format = ticker.FuncFormatter(comma_func)
# Make a bar graph.
x = numpy.arange(len(months)) + 0.25
width = 0.5
pyplot.figure(num=1, figsize=(8,4.5))
pyplot.bar(x, births, width, color='g')
pyplot.title('U.S.A. Births by Month 1995-2002')
pyplot.figtext(0.5, -0.22, 'Data from the National Center for Health Statistics.', horizontalalignment='center', verticalalignment='bottom', style='italic')
pyplot.ylabel('Births')
pyplot.xlabel('Month')
xticks = pyplot.xticks(x + width/2.0, months, rotation='vertical')
pyplot.subplot(111).yaxis.set_major_formatter(comma_format)
pyplot.subplot(111).grid(b=True, axis='y')
pyplot.savefig('Chapter 6.Births by Month.svg', format='svg', bbox_inches='tight')
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse
Captions
Add a one-line explanation of what this file represents