5 import matplotlib.pyplot as plt
6 import matplotlib.dates as mdates
9 url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv'
11 file = 'time_series_19-covid-Confirmed.csv'
13 ######################################################################
15 if not os.path.isfile(file) or os.path.getmtime(file) < time.time() - 86400:
16 print('Retrieving file')
17 urllib.request.urlretrieve(url, file)
19 ######################################################################
21 with open(file, newline='') as csvfile:
22 reader = csv.reader(csvfile, delimiter=',')
26 for row_nb, row in enumerate(reader):
27 for col_nb, field in enumerate(row):
28 if row_nb >= 1 and col_nb == 1:
30 if not country in nb_cases:
31 nb_cases[country] = numpy.zeros(len(times))
33 if row_nb == 0 and col_nb >= time_col:
34 times.append(time.mktime(time.strptime(field, '%m/%d/%y')))
35 if row_nb == 1 and col_nb == time_col:
36 nb_cases['World'] = numpy.zeros(len(times))
38 if col_nb >= time_col:
39 nb_cases['World'][col_nb - time_col] += int(field)
40 nb_cases[country][col_nb - time_col] += int(field)
42 ######################################################################
45 ax = fig.add_subplot(1, 1, 1)
48 ax.yaxis.grid(color='gray', linestyle='-', linewidth=0.25)
49 ax.set_title('Nb. of COVID-19 cases')
50 ax.set_xlabel('Date', labelpad = 10)
53 myFmt = mdates.DateFormatter('%b %d')
54 ax.xaxis.set_major_formatter(myFmt)
55 dates = mdates.epoch2num(times)
57 for key, color, label, delta in [
58 ('World', 'blue', 'World', 0),
59 ('Switzerland', 'red', 'Switzerland', 14),
60 ('France', 'lightgreen', 'France', 11),
61 ('US', 'black', 'USA', 14),
62 ('Korea, South', 'gray', 'S. Korea', 0),
63 ('Italy', 'purple', 'Italy', 3),
64 ('China', 'orange', 'China', 0)
67 ax.plot(dates[:dates.shape[0]-delta], nb_cases[key][delta:], color = color, label = label, linewidth=2)
69 # ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon = False)
70 ax.legend(frameon = False)
73 # fig.savefig('covid19.svg')
75 ######################################################################