Done deaths for UK nations
[covid19.git] / uk_deaths.md
index 76ca621b134af706405f3554c785d3718b2ddcd4..da577be1e206636b31d53ea5bc43f0ef8307a599 100644 (file)
@@ -312,6 +312,10 @@ deaths_headlines
 ```
 
 ```python
+deaths_headlines_e['previous_mean'] = deaths_headlines_e['total_2019 total_2018 total_2017 total_2016 total_2015'.split()].apply(np.mean, axis=1)
+deaths_headlines_w['previous_mean'] = deaths_headlines_w['total_2019 total_2018 total_2017 total_2016 total_2015'.split()].apply(np.mean, axis=1)
+deaths_headlines_s['previous_mean'] = deaths_headlines_s['total_2019 total_2018 total_2017 total_2016 total_2015'.split()].apply(np.mean, axis=1)
+deaths_headlines_i['previous_mean'] = deaths_headlines_i['total_2019 total_2018 total_2017 total_2016 total_2015'.split()].apply(np.mean, axis=1)
 deaths_headlines['previous_mean'] = deaths_headlines['total_2019 total_2018 total_2017 total_2016 total_2015'.split()].apply(np.mean, axis=1)
 deaths_headlines
 ```
@@ -321,7 +325,12 @@ deaths_headlines['total_2020 total_2019 total_2018 total_2017 total_2016 total_2
 ```
 
 ```python
-Radar plot code taken f
+deaths_headlines_i.plot()
+```
+
+```python
+# Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#
+
 fig = plt.figure(figsize=(10, 10))
 ax = fig.add_subplot(111, projection="polar")
 
@@ -363,10 +372,165 @@ plt.savefig('deaths-radar.png')
 plt.show()
 ```
 
+# Excess deaths calculation
+
 ```python
 (deaths_headlines.loc[12:].total_2020 - deaths_headlines.loc[12:].previous_mean).sum()
 ```
 
+```python
+# Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#
+
+fig = plt.figure(figsize=(10, 10))
+ax = fig.add_subplot(111, projection="polar")
+
+theta = np.roll(
+    np.flip(
+        np.arange(len(deaths_headlines_e))/float(len(deaths_headlines_e))*2.*np.pi),
+    14)
+l15, = ax.plot(theta, deaths_headlines_e['total_2015'], color="#e47d7d", label="2015") # 0
+l16, = ax.plot(theta, deaths_headlines_e['total_2016'], color="#afc169", label="2016") # 72 , d0e47d
+l17, = ax.plot(theta, deaths_headlines_e['total_2017'], color="#7de4a6", label="2017") # 144
+l18, = ax.plot(theta, deaths_headlines_e['total_2018'], color="#7da6e4", label="2018") # 216
+l19, = ax.plot(theta, deaths_headlines_e['total_2019'], color="#d07de4", label="2019") # 288
+
+lmean, = ax.plot(theta, deaths_headlines_e['previous_mean'], color="black", linestyle='dashed', label="mean")
+
+l20, = ax.plot(theta, deaths_headlines_e['total_2020'], color="red", label="2020")
+
+# deaths_headlines.total_2019.plot(ax=ax)
+
+def _closeline(line):
+    x, y = line.get_data()
+    x = np.concatenate((x, [x[0]]))
+    y = np.concatenate((y, [y[0]]))
+    line.set_data(x, y)
+
+[_closeline(l) for l in [l19, l18, l17, l16, l15, lmean]]
+
+
+ax.set_xticks(theta)
+ax.set_xticklabels(deaths_headlines_e.index)
+plt.legend()
+plt.title("Deaths by week over years, England")
+plt.savefig('deaths-radar_england.png')
+plt.show()
+```
+
+```python
+# Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#
+
+fig = plt.figure(figsize=(10, 10))
+ax = fig.add_subplot(111, projection="polar")
+
+theta = np.roll(
+    np.flip(
+        np.arange(len(deaths_headlines_w))/float(len(deaths_headlines_w))*2.*np.pi),
+    14)
+l15, = ax.plot(theta, deaths_headlines_w['total_2015'], color="#e47d7d", label="2015") # 0
+l16, = ax.plot(theta, deaths_headlines_w['total_2016'], color="#afc169", label="2016") # 72 , d0e47d
+l17, = ax.plot(theta, deaths_headlines_w['total_2017'], color="#7de4a6", label="2017") # 144
+l18, = ax.plot(theta, deaths_headlines_w['total_2018'], color="#7da6e4", label="2018") # 216
+l19, = ax.plot(theta, deaths_headlines_w['total_2019'], color="#d07de4", label="2019") # 288
+
+lmean, = ax.plot(theta, deaths_headlines_w['previous_mean'], color="black", linestyle='dashed', label="mean")
+
+l20, = ax.plot(theta, deaths_headlines_w['total_2020'], color="red", label="2020")
+
+
+def _closeline(line):
+    x, y = line.get_data()
+    x = np.concatenate((x, [x[0]]))
+    y = np.concatenate((y, [y[0]]))
+    line.set_data(x, y)
+
+[_closeline(l) for l in [l19, l18, l17, l16, l15, lmean]]
+
+
+ax.set_xticks(theta)
+ax.set_xticklabels(deaths_headlines_w.index)
+plt.legend()
+plt.title("Deaths by week over years, Wales")
+plt.savefig('deaths-radar_wales.png')
+plt.show()
+```
+
+```python
+# Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#
+
+fig = plt.figure(figsize=(10, 10))
+ax = fig.add_subplot(111, projection="polar")
+
+theta = np.roll(
+    np.flip(
+        np.arange(len(deaths_headlines_s))/float(len(deaths_headlines_s))*2.*np.pi),
+    14)
+l15, = ax.plot(theta, deaths_headlines_s['total_2015'], color="#e47d7d", label="2015") # 0
+l16, = ax.plot(theta, deaths_headlines_s['total_2016'], color="#afc169", label="2016") # 72 , d0e47d
+l17, = ax.plot(theta, deaths_headlines_s['total_2017'], color="#7de4a6", label="2017") # 144
+l18, = ax.plot(theta, deaths_headlines_s['total_2018'], color="#7da6e4", label="2018") # 216
+l19, = ax.plot(theta, deaths_headlines_s['total_2019'], color="#d07de4", label="2019") # 288
+
+lmean, = ax.plot(theta, deaths_headlines_s['previous_mean'], color="black", linestyle='dashed', label="mean")
+
+l20, = ax.plot(theta, deaths_headlines_s['total_2020'], color="red", label="2020")
+
+
+def _closeline(line):
+    x, y = line.get_data()
+    x = np.concatenate((x, [x[0]]))
+    y = np.concatenate((y, [y[0]]))
+    line.set_data(x, y)
+
+[_closeline(l) for l in [l19, l18, l17, l16, l15, lmean]]
+
+
+ax.set_xticks(theta)
+ax.set_xticklabels(deaths_headlines_s.index)
+plt.legend()
+plt.title("Deaths by week over years, Scotland")
+plt.savefig('deaths-radar_scotland.png')
+plt.show()
+```
+
+```python
+# Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#
+
+fig = plt.figure(figsize=(10, 10))
+ax = fig.add_subplot(111, projection="polar")
+
+theta = np.roll(
+    np.flip(
+        np.arange(len(deaths_headlines_i))/float(len(deaths_headlines_i))*2.*np.pi),
+    14)
+l15, = ax.plot(theta, deaths_headlines_i['total_2015'], color="#e47d7d", label="2015") # 0
+l16, = ax.plot(theta, deaths_headlines_i['total_2016'], color="#afc169", label="2016") # 72 , d0e47d
+l17, = ax.plot(theta, deaths_headlines_i['total_2017'], color="#7de4a6", label="2017") # 144
+l18, = ax.plot(theta, deaths_headlines_i['total_2018'], color="#7da6e4", label="2018") # 216
+l19, = ax.plot(theta, deaths_headlines_i['total_2019'], color="#d07de4", label="2019") # 288
+
+lmean, = ax.plot(theta, deaths_headlines_i['previous_mean'], color="black", linestyle='dashed', label="mean")
+
+l20, = ax.plot(theta, deaths_headlines_i['total_2020'], color="red", label="2020")
+
+
+def _closeline(line):
+    x, y = line.get_data()
+    x = np.concatenate((x, [x[0]]))
+    y = np.concatenate((y, [y[0]]))
+    line.set_data(x, y)
+
+[_closeline(l) for l in [l19, l18, l17, l16, l15, lmean]]
+
+
+ax.set_xticks(theta)
+ax.set_xticklabels(deaths_headlines_i.index)
+plt.legend()
+plt.title("Deaths by week over years, Northern Ireland")
+plt.savefig('deaths-radar_northern_ireland.png')
+plt.show()
+```
+
 ```python
 
 ```