From 15fc29253cbcf40c8f00de4f9c31a3eaa8cb78b6 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Thu, 12 Mar 2020 17:31:29 +0100 Subject: [PATCH] Update. --- covid19.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/covid19.py b/covid19.py index ea79544..ef9e393 100755 --- a/covid19.py +++ b/covid19.py @@ -5,7 +5,7 @@ # Written by Francois Fleuret -import os, time, math +import os, time import numpy, csv import matplotlib.pyplot as plt import matplotlib.dates as mdates @@ -13,7 +13,7 @@ import urllib.request url = 'https://github.com/CSSEGISandData/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv' -file = 'time_series_19-covid-Confirmed.csv' +file = url[url.rfind('/')+1:] ###################################################################### @@ -36,13 +36,16 @@ with open(file, newline='') as csvfile: nb_cases[country] = numpy.zeros(len(times)) 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) +countries = list(nb_cases.keys()) +countries.sort() +print('Countries: ', countries) + +nb_cases['World'] = sum(nb_cases.values()) + ###################################################################### fig = plt.figure() @@ -54,12 +57,10 @@ 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) -print('Countries:') -print(nb_cases.keys()) - for key, color, label in [ ('World', 'blue', 'World'), ('Switzerland', 'red', 'Switzerland'), @@ -74,6 +75,7 @@ for key, color, label in [ ax.legend(frameon = False) plt.show() + fig.savefig('covid19.png') ###################################################################### -- 2.39.5