DescriptionUS Labor Participation Rate 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.
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
Other versions
Source code
#!/usr/bin/env python### Create an SVG graph of BLS timeseries data using matplotlib and # BeautifulSoup.#importmatplotlib.figureimportdatetimeimportbs4importmatplotlib.backends.backend_cairoimportstringimporturllib2defmain():url='http://data.bls.gov/timeseries/%s?years_option=specific_years&include_graphs=true&to_year=2011&from_year=1948'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.#defscrape_bls(soup):table=soup.find_all('table',attrs={'class':'regular-data'})assertlen(table)==1table=table[0]data=[]years_lc=[[tfortinriftype(t)isbs4.element.Tag]forrintable.contents[4]iftype(r)isbs4.element.Tag]forrowinyears_lc:year=int(row[0].text)months=[float(t.text)fortinrow[1:]ifany(cinstring.printableandc!=' 'forcint.text)]data.append((year,months))returndata### Add plot to figure. Extra parameters are passed to # matplotlib.axes.Axes.plot().#defadd_plot(axis,data,*args):x=[]y=[]foryear,monthsindata:formonth,ninenumerate(months):x.append(datetime.date(year,month+1,1))y.append(n)axis.plot(x,y,*args)### Initialize figure.#definit_figure():figure=matplotlib.figure.Figure()axis=figure.add_subplot(111)axis.xaxis.set_major_locator(matplotlib.dates.YearLocator(6))axis.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y'))axis.grid(True)returnfigure,axis### Save figure#defsave_figure(figure,filename):figure.canvas=matplotlib.backends.backend_cairo.FigureCanvasCairo(figure)figure.savefig(filename,transparent=True)if__name__=="__main__":main()
Captions
Add a one-line explanation of what this file represents
{{Information |Description={{en|1=Graph of US Civilian Labor Participaton Rate from 1948 to 2010 by gender}} |Source=Bureau of Labor Statistics within the [[:wikipedia:United States Department of Labor|United Stat
File usage
No pages on the English Wikipedia use this file (pages on other projects are not listed).