Checked content

File:US Labor Participation Rate 1948-2011 by gender.svg

English: Graph of US Civilian Labor Participation Rate from 1948 to 2011 by gender. Men are represented in light blue, women in pink, and the total in black.
Date 8 October 2011
Source Bureau of Labor Statistics within the United States Department of Labor
Author User:Int21h
( Reusing this file)
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her 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.

Source code

#!/usr/bin/env python
# Create an SVG graph of BLS timeseries data using matplotlib and 
# BeautifulSoup.
import matplotlib.figure
import datetime
import bs4
import matplotlib.backends.backend_cairo
import string
import urllib2
def main():
        url = ''
        total_series = 'LNS11300000'
        men_series = 'LNS11300001'
        women_series = 'LNS11300002'
        fig,ax = init_figure()
        add_plot(ax, scrape_bls(bs4.BeautifulSoup(urllib2.urlopen(url % total_series))), 'black')
        add_plot(ax, scrape_bls(bs4.BeautifulSoup(urllib2.urlopen(url % men_series))), 'lightblue')
        add_plot(ax, scrape_bls(bs4.BeautifulSoup(urllib2.urlopen(url % women_series))), 'pink')
        save_figure(fig, 'US Labor Participation Rate 1948-2011 by gender.svg')
# Scrape the BLS soup for the data.
def scrape_bls(soup):
        table = soup.find_all('table', attrs={'class': 'regular-data'})
        assert len(table) == 1
        table = table[0]
        data = []
        years_lc = [[t for t in r if type(t) is bs4.element.Tag] for r in table.contents[4] if type(r) is bs4.element.Tag]
        for row in years_lc:
                year = int(row[0].text)
                months = [float(t.text) for t in row[1:] if any(c in string.printable and c != ' ' for c in t.text)]
        return data
# Add plot to figure. Extra parameters are passed to 
# matplotlib.axes.Axes.plot().
def add_plot(axis, data, *args):
        for year,months in data:
                for month,n in enumerate(months):
                        x.append(, month+1, 1))
        axis.plot(x, y, *args)
# Initialize figure.
def init_figure():
        figure = matplotlib.figure.Figure()
        axis = figure.add_subplot(111)
        return figure,axis
# Save figure
def save_figure(figure, filename):
        figure.canvas = matplotlib.backends.backend_cairo.FigureCanvasCairo(figure)
        figure.savefig(filename, transparent=True)
if __name__ == "__main__":
The following pages on Schools Wikipedia link to this image (list may be incomplete):


Did you know...?

Through Schools Wikipedia, SOS Childrens Villages has brought learning to children around the world. SOS Childrens Villages is an international children's charity, providing a good home and loving family to thousands of children who have lost their parents. We also work with communities to help vulnerable families stay together and raise children in the best possible environment. Try to find out how you can help children in other countries on our web site.