X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=covid19.py;h=ef9e39316c9059ab9d9a410bb082a1bcd46bb317;hb=15fc29253cbcf40c8f00de4f9c31a3eaa8cb78b6;hp=b3774589e0eeccbdc5c976b510693d2bafc27f2c;hpb=06a756efa8ea977bd28725a3b5e580040a03367d;p=python.git diff --git a/covid19.py b/covid19.py index b377458..ef9e393 100755 --- a/covid19.py +++ b/covid19.py @@ -1,14 +1,19 @@ #!/usr/bin/env python -import os, time, math +# Any copyright is dedicated to the Public Domain. +# https://creativecommons.org/publicdomain/zero/1.0/ + +# Written by Francois Fleuret + +import os, time 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' +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:] ###################################################################### @@ -29,47 +34,48 @@ with open(file, newline='') as csvfile: 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) +countries = list(nb_cases.keys()) +countries.sort() +print('Countries: ', countries) + +nb_cases['World'] = sum(nb_cases.values()) + ###################################################################### fig = plt.figure() ax = fig.add_subplot(1, 1, 1) -# ax.grid ax.yaxis.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 key, color, label, delta in [ - ('World', 'blue', 'World', 0), - ('Switzerland', 'red', 'Switzerland', 14), - ('France', 'lightgreen', 'France', 11), - ('US', 'black', 'USA', 14), - ('Korea, South', 'gray', 'S. Korea', 0), - ('Italy', 'purple', 'Italy', 3), - ('China', 'orange', 'China', 0) +for key, color, label in [ + ('World', 'blue', 'World'), + ('Switzerland', 'red', 'Switzerland'), + ('France', 'lightgreen', 'France'), + ('US', 'black', 'USA'), + ('Korea, South', 'gray', 'South Korea'), + ('Italy', 'purple', 'Italy'), + ('China', 'orange', 'China') ]: - delta = 0 - ax.plot(dates[:dates.shape[0]-delta], nb_cases[key][delta:], color = color, label = label, linewidth=2) + ax.plot(dates, nb_cases[key], color = color, label = label, linewidth=2) -# ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon = False) ax.legend(frameon = False) plt.show() -# fig.savefig('covid19.svg') + +fig.savefig('covid19.png') ######################################################################