From 0db243241c0ec4515e6484ad3e7195dc3f015e8b Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Mon, 9 Mar 2020 17:07:25 +0100 Subject: [PATCH 1/1] Initial commit. --- covid19.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 covid19.py diff --git a/covid19.py b/covid19.py new file mode 100755 index 0000000..0fd9ecc --- /dev/null +++ b/covid19.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +import os, time, math +import numpy, csv +import matplotlib.pyplot as plt +import matplotlib.dates as mdates +import urllib.request + +url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv' + +file = 'time_series_19-covid-Confirmed.csv' + +###################################################################### + +if not os.path.isfile(file) or os.path.getmtime(file) < time.time() - 86400: + print('Retrieving file') + urllib.request.urlretrieve(url, file) + +###################################################################### + +with open(file, newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=',') + times = [] + nb_cases = {} + time_col = 5 + for row_nb, row in enumerate(reader): + for col_nb, field in enumerate(row): + if row_nb >= 1 and col_nb == 1: + country = field + if not country in nb_cases: + nb_cases[country] = numpy.zeros(len(times)) + # print(country) + if row_nb == 0 and col_nb >= time_col: + times.append(time.mktime(time.strptime(field, '%m/%d/%y'))) + if row_nb == 1 and col_nb == time_col: + nb_cases['World'] = numpy.zeros(len(times)) + if row_nb >= 1: + if col_nb >= time_col: + nb_cases['World'][col_nb - time_col] += int(field) + nb_cases[country][col_nb - time_col] += int(field) + +###################################################################### + +fig = plt.figure() +ax = fig.add_subplot(1, 1, 1) + +ax.grid(color='gray', linestyle='-', linewidth=0.25) + +ax.set_title('Nb. of COVID-19 cases') +ax.set_xlabel('Date', labelpad = 10) +ax.set_yscale('log') + +myFmt = mdates.DateFormatter('%b %d') +ax.xaxis.set_major_formatter(myFmt) +dates = mdates.epoch2num(times) + +for label, color in [ ('World', 'blue'), + ('Switzerland', 'red'), + ('France', 'green'), + ('South Korea', 'gray'), + ('Mainland China', 'orange') ]: + ax.plot(dates, nb_cases[label], color = color, label = label) + +# ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon = False) +ax.legend(frameon = False) + +plt.show() +# fig.savefig('covid19.svg') + +###################################################################### -- 2.39.5