Monthly Archives: August 2017

Visual Communication in Python: Pie Charts with Matplotlib

A personal story about how I started using Python for my research: when I was a post-doc at Microsoft, I was embarrassed to ask them to buy me Matlab. But I knew how to plot things in Matlab and I didn’t have time to learn how to make a graphic look nice with Excel or whatever the preferred Microsoft tool was at the time. Matplotlib to the rescue. It was free, it looked *better* than Matlab, and then it was done.

As readers of this blog may know, I have come to use Python extensive in my research by now. But one thing that I have not changed in the 10 years since that post-doc experience is using matplotlib like it was Matlab. It might be time to change.

I recently read a short blog on the modern approach to using Matplotlib, http://pbpython.com/effective-matplotlib.html, and it seems worth a try. Do you remember a talk on data visualization I gave last fall? https://github.com/aflaxman/iths-communicating-results-visually-2

I’m going to try remaking the plots I spoke on with my old school mpl and the modern approach. Here is the first, a pie chart.

My old-fashioned way is in a notebook from my talk, and looks like this:

plt.figure(figsize=(9,8))
plt.subplots_adjust(hspace=.3, right=.8, left=.1)
plt.pie([2,98], labels=['Survived\n2%', 'Died\n98%'], colors=colors, startangle=0)

The new way is built up in this notebook here, and ends up being comparable:

fig, ax = plt.subplots(figsize=(9,8))
s.plot(kind='pie', colors=colors, startangle=0)
fig.subplots_adjust(hspace=.3, right=.8, left=.1)
ax.set_ylabel('')

Is that cooler? I’m not convinced, but I’ll keep trying.

Comments Off on Visual Communication in Python: Pie Charts with Matplotlib

Filed under dataviz

To read: Building Sustainable Financing Structures for Population Health: Insights from Non-Health Sectors

https://www.nap.edu/catalog/24760/building-sustainable-financing-structures-for-population-health-insights-from-non

Comments Off on To read: Building Sustainable Financing Structures for Population Health: Insights from Non-Health Sectors

Filed under Uncategorized

Righter signatures in Jupyter

Did you know you can change the signature of functions dynamically in Python 3? It is a bit nasty, and maybe will make things look nicer for vivarium users.

Attempt: https://github.com/ihmeuw/vivarium/pull/2
Docs: https://docs.python.org/3/library/inspect.html#inspect.Signature
SO question that got me started: https://stackoverflow.com/a/33112180/1935494

Comments Off on Righter signatures in Jupyter

Filed under Uncategorized

Introducing Vivarium

I’ve had a new line of research developing for the last 18 months or so—*microsimulation*. It started when I stepped in to help with the “Cost Effectiveness Analysis with Microsimulation” (or CEAM) project at IHME. Now it is growing and growing to take over all of my research and recreation time. Is that bad or good?

Some of this work has now seen daylight from our presentations at SummerSim and iHEA in July, and today I am please to introduce a python package that you can use, too.

The programmers I’ve been working with on this convinced me that it is not just for cost effectiveness analysis and we need a more expansive name for it. So I present to you: vivarium. https://github.com/ihmeuw/vivarium

2 Comments

Filed under Uncategorized

MAL-ED study

I needed to get up to speed on this large data collection effort, so I thought I’d collect what I found here, for my own reference and in case it was of interest to others.

> The purpose of this study was to collect longitudinal data on the relationships between malnutrition and enteric infections in children ages 17 days through approximately 2 years.
>
> The data were collected through in-person interviews in the home, anthropometry, cognitive exams, and biological samples. The samples collected included blood, urine, and stool. The households were visited twice weekly for interviews and stool samples. Anthropometric measurements were gathered at monthly intervals. Blood samples were taken at 7 and 15 months of age to assess micronutrient levels and vaccination status. Children underwent the lactulose-mannitol urine test for gut function at 3, 6, 9, 15, and 24 months.
>
> The study was conducted in subnational areas of Bangladesh, Brazil, India, Peru, Pakistan, Nepal, South Africa, and Tanzania. Each site had a sample size of approximately 200 children.

(n = 2,053)

http://ghdx.healthdata.org/search/site/mal-ed

http://ghdx.healthdata.org/series/etiology-risk-factors-and-interactions-enteric-infections-and-malnutrition-and-consequences

http://mal-ed.fnih.org/

https://jhpn.biomedcentral.com/articles/10.1186/s41043-015-0004-2

https://pdfs.semanticscholar.org/af38/f8554f0636113e42f6d34f82347e015381d2.pdf

Comments Off on MAL-ED study

Filed under Uncategorized

I have used IPython Notebooks for my lab book for 5 years

And it is still working well. Here is what I did in my first one:

You think that is mixed yet?

Comments Off on I have used IPython Notebooks for my lab book for 5 years

Filed under Uncategorized

Diversity Club: Third Culture Kids

Hello All,

At diversity club this week a month or so ago, we are going to learn about Third Culture Kids, and you can read about what this is in the short article linked here:
http://www.cmhnetwork.org/media-center/morning-zen/the-trouble-with-third-culture-kids

As supplementary material, here is an infographic and a recent nytimes article:
INFOGRAPHIC: The Modern Third Culture Kid

–Abie and Nina

(I remind you that you can bring your own lunch if you would like to eat while we meet.)

Comments Off on Diversity Club: Third Culture Kids

Filed under Uncategorized