Skip to content

Instantly share code, notes, and snippets.

@vene
Created August 27, 2014 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vene/0d67b3b73e9d994ca037 to your computer and use it in GitHub Desktop.
Save vene/0d67b3b73e9d994ca037 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
deaths = [596577, 142942, 73831, 41374, 39518, 21176, 7683, 6849]
money = [54.1, 7, 4.2, 257.85, 3.2, 147, 14, 22.9]
names = ["Heart disease", "COPS", "Diabetes", "Breast cancer",
"Suicide", "Prostate cancer", "HIV/AIDS", "Motor neuron disease"]
sns.set_style("white")
ypos = np.arange(len(deaths)) + 0.5
plt.subplot(121)
plt.barh(ypos, -np.array(money)[::-1], align="center")
plt.xticks(range(0, -401, -100), (["{}M".format(k) for k in range(0, 401, 100)]))
plt.xlabel("Money raised by the studied campaign (USD)")
for this_y, xval in zip(ypos, money[::-1]):
plt.text(-(xval + 10), this_y, "${}M".format(xval),
horizontalalignment="right")
plt.yticks(())
plt.subplot(122)
plt.barh(ypos, deaths[::-1], align="center")
plt.yticks(ypos, names[::-1], horizontalalignment="center", x=-0.33,
weight="bold")
plt.xticks(range(0, 800001, 200000), (["{}k".format(k)
for k in range(0, 801, 200)]))
plt.xlabel("Deaths in the US")
for this_y, xval in zip(ypos, deaths[::-1]):
plt.text(xval + 10000, this_y, str(xval))
plt.suptitle("Campaign results vs. deaths caused by diseases (source: "
"http://goo.gl/PsXbs0)")
plt.subplots_adjust(left=0.05, right=0.95, wspace=0.75, top=0.93)
plt.savefig("death.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment