-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCovid19_TS1.py
110 lines (104 loc) · 5.44 KB
/
Covid19_TS1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#Figure of CoVid-19 Case in Middlesbrough(Python version)
#Coded by dxb 05-05-2020
#Revise on 06-12-2020
#Update on 06-26-2020
import numpy
import matplotlib.pyplot
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
#import datetime
#Data source Need to update by day
#cases data from the UK government
cases = [1, 1, 1, 3, 7, 9, 13, 17, 19, 26, 33, 44, 59, 74, 92, 111, 126, 151, 169, 196, 213,\
235, 237, 258, 274, 291, 302, 325, 346, 354, 367, 394, 407, 413, 427, 451, 472, 481, 496,\
509, 509, 541, 554, 559, 566, 582, 588, 589, 600, 615, 619, 624, 626, 628, 630, 631, 632,\
633, 634, 634, 638, 645, 652, 656, 659, 665, 667, 668, 670, 673, 676, 676, 676, 677, 678,\
678, 679, 680, 683, 685, 685, 687, 688, 688, 689, 691, 691, 691, 692, 694, 694, 694, 695,\
695, 695, 697, 697, 697, 698]
#deaths data from NHS
dcases = [1, 1, 1, 1, 1, 1, 1, 2, 4, 4, 4, 11, 15, 30, 35, 43, 48, 49, 59, 69, 73, 78, 79, 83,\
83, 100, 106, 122, 126, 134, 134, 134, 141, 151, 157, 157, 166, 166, 166, 172, 178, 180,\
185, 189, 189, 189, 196, 199, 199, 204, 204, 204, 204, 210, 213, 214, 215, 216, 216, 216,\
217, 220, 221, 223, 223, 223, 223, 223, 226, 228, 229, 231, 231, 231, 237, 238, 238, 241,\
241, 241, 241, 245, 246, 248, 248, 248, 248, 248, 250, 250, 250, 251, 251, 251, 251, 253,\
253, 254, 254]
#Initial
#Date config
days = len(cases) #获取list长度
#Data Calculation
casess = cases.copy() #list复制
casess.insert(0,0) #在casess头插入0
casess.pop() #删除list最后一元素
increase = list(map(lambda x: x[0]-x[1], zip(cases, casess))) #用lambda表达式计算list对应元素之差
dcasess = dcases.copy() #list复制
dcasess.insert(0,0) #在casess头插入0
dcasess.pop() #删除list最后一元素
dincrease = list(map(lambda x: x[0]-x[1], zip(dcases, dcasess))) #用lambda表达式计算list对应元素之差
#Average of 5 days calculation
enincrease = increase.copy()
enincrease.insert(0,enincrease[0])
enincrease.insert(0,enincrease[0])
enincrease.insert(-1,enincrease[-1])
enincrease.insert(-1,enincrease[-1])
endincrease = dincrease.copy()
endincrease.insert(0,endincrease[0])
endincrease.insert(0,endincrease[0])
endincrease.insert(-1,endincrease[-1])
endincrease.insert(-1,endincrease[-1])
avincrease = increase.copy()
avdincrease = dincrease.copy()
for i in range(len(avincrease)):
avincrease[i] = (enincrease[i]+enincrease[i+1]+enincrease[i+2]+enincrease[i+3]+enincrease[i+4]) / 5.0
avdincrease[i] = (endincrease[i]+endincrease[i+1]+endincrease[i+2]+endincrease[i+3]+endincrease[i+4]) / 5.0
#Plot
matplotlib.pyplot.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
matplotlib.pyplot.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
#Total cases plot
ax1 = matplotlib.pyplot.subplot(2,1,1)
ax1.plot(cases, linewidth='1', color='blue', linestyle='-', marker='*', label="总确诊数 Total Cases")
ax1.plot(dcases, linewidth='1', color='red', linestyle='-', marker='o', label="总死亡数 Total Death")
matplotlib.pyplot.title('米德尔斯堡新冠病毒累计确诊及詹姆斯库克大学医院累计死亡病例\n\
Total Comfirmed Cases of CoVID-19 in Middlesbrough & Total Dead Cases at the James Cook University Hospital')
matplotlib.pyplot.ylabel('病例数 Cases')
matplotlib.pyplot.xlabel('天数 Days')
ax1.legend(loc = 'upper left')
step1 = 5
while (max(cases)/16)>step1:
step1 = step1 + 5
matplotlib.pyplot.ylim(0, step1*16)
matplotlib.pyplot.xlim(0, len(cases)-1)
ax1.yaxis.set_major_locator(MultipleLocator(step1*2))
ax1.yaxis.set_minor_locator(MultipleLocator(step1))
ax1.yaxis.grid(True, which='both')
ax1.xaxis.grid(True)
ax2 = matplotlib.pyplot.subplot(2,1,2)
ax2.plot(increase, linewidth='0.5', color='cadetblue', linestyle=':', marker='*', label = "新增确诊 Daily Cases")
ax2.plot(avincrease, linewidth='1', color='blue', linestyle='-', label = '确诊5日均值 Average of 5 days Cases')
ax2.plot(dincrease, linewidth='1', color='pink', linestyle=':', marker='o', label = '新增死亡 Daily Deaths')
ax2.plot(avdincrease, linewidth='1', color='red', linestyle='-', label = '死亡5日均值 Average of 5 days Deaths')
ax2.legend(loc = 'upper right')
matplotlib.pyplot.title('米德尔斯堡新冠病毒日增确诊及詹姆斯库克大学医院日增死亡病例\n\
Daily Comfirmed Cases of CoVID-19 in Middlesbrough & Daily Dead Cases at the James Cook University Hospital')
matplotlib.pyplot.ylabel('病例数 Cases')
matplotlib.pyplot.xlabel('天数 Days')
step2 = 2
while ((max(increase)-min(increase))/16)>step2:
step2 = step2 + 1
print(step2)
matplotlib.pyplot.ylim(min(0,min(increase)), step2*16)
matplotlib.pyplot.xlim(0, len(increase)-1)
ax2.yaxis.set_major_locator(MultipleLocator(step2*2))
ax2.yaxis.set_minor_locator(MultipleLocator(step2))
ax2.yaxis.grid(True, which='both')
ax2.xaxis.grid(True)
matplotlib.pyplot.grid(True)
figManager = matplotlib.pyplot.get_current_fig_manager()
figManager.resize(*figManager.window.maxsize())
matplotlib.pyplot.subplots_adjust(left=0.05, right=0.99, top=0.9, bottom=0.08, wspace=0, hspace=0.4)
# Show and save figure
fig = matplotlib.pyplot.gcf()
fig.show() #Ensure png save in right scale
print('savefig in png...')
fig.savefig('COVID19_TS1.png')
matplotlib.pyplot.show() #Ensure pdf save in right scale
print('savefig in pdf...')
fig.savefig('COVID19_TS1.pdf')