Created
June 26, 2020 01:28
-
-
Save alexklapheke/5077fe330ca6a307b8700d0af4c4adf9 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
#!/usr/bin/env python3 | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from matplotlib.dates import MonthLocator | |
plt.style.use("alex") | |
# Read in & parse data | |
nyt = pd.read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv", parse_dates=["date"]) | |
nyc = nyt[(nyt["state"] == "New York") & (nyt["county"] == "New York City")] | |
hou = nyt[(nyt["state"] == "Texas") & (nyt["county"] == "Harris")] | |
# Set plot parameters | |
fig, axs = plt.subplots(1, 2, figsize=(8, 3)) | |
colors = {"cases": "#081220", "deaths": "#CE2A07"} | |
titles = ["New York City", "Harris County, Texas"] | |
lockdowns = [ | |
("2020-03-22", "2020-06-22"), # NY | |
("2020-04-02", "2020-04-30") # TX | |
] | |
leftmost = True | |
for ax, data, title, lockdown in zip(axs, [nyc, hou], titles, lockdowns): | |
for col in ["cases", "deaths"]: | |
ax.plot(data["date"], data[col] / 1000, color=colors[col]) | |
ax.annotate("{:,}".format(data[col].max()), | |
xy=( | |
data["date"].max() + pd.DateOffset(2), | |
data[col].max() / 1000 - 1 | |
), color=colors[col]) | |
ax.set_title(title) | |
ax.set_ylim(0, 250) | |
ax.set_yticks([100, 200] if leftmost else []) | |
ax.xaxis.set_major_locator(MonthLocator()) | |
ax.yaxis.set_major_formatter(plt.FormatStrFormatter("%dk")) | |
ax.axvspan(*map(pd.to_datetime, lockdown), color="#e8e8e8") | |
leftmost = False | |
plt.savefig("covid-nyc-hou.svg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment