From: Francois Fleuret Date: Thu, 12 Mar 2020 16:31:29 +0000 (+0100) Subject: Update. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=15fc29253cbcf40c8f00de4f9c31a3eaa8cb78b6;p=python.git Update. --- 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') ######################################################################