Created
August 27, 2014 09:57
-
-
Save vene/0d67b3b73e9d994ca037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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