Skip to content

Instantly share code, notes, and snippets.

@Spationaute
Created April 23, 2020 14:22
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 Spationaute/9b5ee0f3ad17cad57da3f06613c37348 to your computer and use it in GitHub Desktop.
Save Spationaute/9b5ee0f3ad17cad57da3f06613c37348 to your computer and use it in GitHub Desktop.
Small script to plot data from the Johns Hopkins CSSE github
#/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import pandas as ps
import itertools as it
plt.ion()
data = ps.read_csv('time_series_covid19_confirmed_global.csv',parse_dates=True)
data_death = ps.read_csv('time_series_covid19_deaths_global.csv',parse_dates=True)
data_healt = ps.read_csv('time_series_covid19_recovered_global.csv',parse_dates=True)
countries_avail = data["Country/Region"]
date_available = data.keys()[4:]
filt = ["Canada","Germany","Korea*","Taiwan","US","Italy","France","Japan","Iran","UK","Spain","China"]
countries_avail = countries_avail[countries_avail.isin(filt)]
count = 1
#for country in it.cycle(set(countries_avail.values)):
for country in set(countries_avail.values):
day_total = data[data["Country/Region"]==country][date_available].sum()
day_death = data_death[data_death["Country/Region"]==country][date_available].sum()
day_healt = data_healt[data_healt["Country/Region"]==country][date_available].sum()
day_still = day_total-day_healt-day_death
plt.subplot(2,1,1)
plt.title("{} COVID19 Growth".format(country))
plt.grid(True)
plt.xlim( [0,len(day_total.values)])
plt.bar(range(len(day_total.values)),day_total.values,zorder=3,label="Cases")
plt.bar(range(len(day_death.values)),day_death.values,zorder=3,label="Death")
plt.bar(range(len(day_healt.values)),day_healt.values,bottom=day_death.values,zorder=3,label="Recovered")
plt.legend(loc='upper left')
#plt.tick_params(
# axis='x',
# which='both',
# labelbottom=False)
plt.xticks(range(0,len(day_total.values),10),day_total.keys()[::10])
#plt.xlabel("Day")
plt.ylabel("Cases Total")
plt.subplot(2,1,2)
plt.grid(True)
plt.xlim( [0,len(day_total.values)])
plt.bar(range(len(day_total.values)),day_total.diff().values,zorder=3,label="Cases")
plt.bar(range(len(day_death.values)),day_death.diff().values,zorder=3,label="Death")
plt.bar(range(len(day_healt.values)),day_healt.diff().values,bottom=day_death.diff().values,zorder=3,label="Recovered")
plt.tick_params(
axis='x',
which='both',
labelbottom=False)
plt.xlabel("Day")
plt.ylabel("Change")
plt.tight_layout(pad=1.2)
plt.savefig("graph/{}.png".format(country))
print(" Graph for {} ready".format(country))
#plt.show()
# plt.pause(6)
plt.clf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment