Skip to content

Instantly share code, notes, and snippets.

@brsr
Last active April 28, 2020 00:15
Show Gist options
  • Save brsr/51e0487b2f84691490a1b3c6b1c22354 to your computer and use it in GitHub Desktop.
Save brsr/51e0487b2f84691490a1b3c6b1c22354 to your computer and use it in GitHub Desktop.
Plot of Delphi's COVID-19 symptoms survey data for Oneida County, NY
import numpy as np
import matplotlib.pyplot as plt
#module downloaded from https://github.com/cmu-delphi/delphi-epidata/blob/master/src/client/delphi_epidata.py
from delphi_epidata import Epidata
#see https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html for API details
#oneida county: geo_type='county', geo_value='36065'
#queens: geo_type='county', geo_value='36081'
#NY state: geo_type='state', geo_value='NY'
res = Epidata.covidcast(data_source='fb-survey', signal='smoothed_cli',
time_type='day', geo_type='county',
time_values='20200301-20200431', geo_value='36065')
time = np.array([x['time_value'] for x in res['epidata']]) - 20200400
value = np.array([x['value'] for x in res['epidata']])
stderr = np.array([x['stderr'] for x in res['epidata']])
lowend = value - 2 * stderr
lowend[lowend < 0] = 0
highend = value + 2 * stderr
highstack = highend - lowend
fig, ax = plt.subplots(figsize=(10, 5))
ax.stackplot(time, [lowend, highstack], colors=['w', 'lightblue'],
labels = [None, 'Confidence interval'])
ax.scatter(time, value, color='k', label='Estimate')
ax.set_xticks(np.linspace(6, 26, 21))
ax.set_ylim(0, 3.5)
ax.set_xlabel('Day in April')
ax.set_ylabel('Percent with symptoms')
ax.legend()
fig.suptitle('Oneida County')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment