-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotItalianBreakdown.py
103 lines (86 loc) · 6.42 KB
/
plotItalianBreakdown.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
import pandas as pd
import matplotlib.pyplot as plt
import sys
import dateutil
import numpy as np
import os
import matplotlib.dates as mdates
if not os.path.isdir("plots"):
os.mkdir("plots")
df = pd.read_csv("https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv")
df["data"] = pd.to_datetime(df["data"])
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
df_fullbreakdown = df[["data", "tamponi","terapia_intensiva", "ricoverati_con_sintomi", "isolamento_domiciliare","dimessi_guariti", "deceduti"]]
df_fullbreakdown["negativi"] = df_fullbreakdown["tamponi"] - df_fullbreakdown["terapia_intensiva"] - df_fullbreakdown["ricoverati_con_sintomi"] - df_fullbreakdown["isolamento_domiciliare"] - df_fullbreakdown["dimessi_guariti"] - df_fullbreakdown["deceduti"]
df_fullbreakdown = df_fullbreakdown.drop("tamponi", 1)
# ax = df_fullbreakdown.plot.bar(x="data", stacked=True) borken
ax.bar(df_fullbreakdown.data, df_fullbreakdown.terapia_intensiva, color="tab:red")
ax.bar(df_fullbreakdown.data, df_fullbreakdown.ricoverati_con_sintomi, bottom=df_fullbreakdown.terapia_intensiva, color="tab:orange")
ax.bar(df_fullbreakdown.data, df_fullbreakdown.isolamento_domiciliare, bottom=df_fullbreakdown.terapia_intensiva + df_fullbreakdown.ricoverati_con_sintomi, color="tab:blue")
ax.bar(df_fullbreakdown.data, df_fullbreakdown.dimessi_guariti, bottom=df_fullbreakdown.terapia_intensiva + df_fullbreakdown.ricoverati_con_sintomi + df_fullbreakdown.isolamento_domiciliare, color="tab:green")
ax.bar(df_fullbreakdown.data, df_fullbreakdown.deceduti, bottom=df_fullbreakdown.terapia_intensiva + df_fullbreakdown.ricoverati_con_sintomi + df_fullbreakdown.isolamento_domiciliare + df_fullbreakdown.dimessi_guariti, color="tab:brown")
ax.bar(df_fullbreakdown.data, df_fullbreakdown.negativi, bottom=df_fullbreakdown.terapia_intensiva + df_fullbreakdown.ricoverati_con_sintomi + df_fullbreakdown.isolamento_domiciliare + df_fullbreakdown.dimessi_guariti + df_fullbreakdown.deceduti, color="tab:purple")
ax.xaxis_date()
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%d/%m"))
ax.set_title("Italian tests breakdown")
ax.set_ylabel("# tests")
ax.legend(["ICU cases", "Hospitalised w/ symptoms", "Quarantined at home", "Recoveries", "Deaths", "Negatives"])
ax.grid(axis="y")
fig.savefig("plots/Italy_FullBreakdown_EN.png")
ax.set_title("Casistica dei tamponi in Italia")
ax.set_ylabel("# tamponi")
ax.legend(["Terapia intensiva", "Ricoverati con sintomi", "Isolamento domiciliare", "Guariti", "Morti", "Negativi"])
ax.grid(axis="y")
fig.savefig("plots/Italy_FullBreakdown_IT.png")
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
df_breakdown = df[["data", "terapia_intensiva", "ricoverati_con_sintomi", "isolamento_domiciliare","dimessi_guariti", "deceduti"]]
# ax = df_breakdown.plot.bar(x="data", stacked=True) borken
ax.bar(df_breakdown.data, df_breakdown.terapia_intensiva, color="tab:red")
ax.bar(df_breakdown.data, df_breakdown.ricoverati_con_sintomi, bottom=df_breakdown.terapia_intensiva, color="tab:orange")
ax.bar(df_breakdown.data, df_breakdown.isolamento_domiciliare, bottom=df_breakdown.terapia_intensiva + df_breakdown.ricoverati_con_sintomi, color="tab:blue")
ax.bar(df_breakdown.data, df_breakdown.dimessi_guariti, bottom=df_breakdown.terapia_intensiva + df_breakdown.ricoverati_con_sintomi + df_breakdown.isolamento_domiciliare, color="tab:green")
ax.bar(df_breakdown.data, df_breakdown.deceduti, bottom=df_breakdown.terapia_intensiva + df_breakdown.ricoverati_con_sintomi + df_breakdown.isolamento_domiciliare + df_breakdown.dimessi_guariti, color="tab:brown")
ax.xaxis_date()
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%d/%m"))
ax.set_title("Italian tests breakdown (excluding negatives)")
ax.set_ylabel("# tests")
ax.legend(["ICU cases", "Hospitalised w/ symptoms", "Quarantined at home", "Recoveries", "Deaths", "Negatives"])
ax.grid(axis="y")
fig.savefig("plots/Italy_Breakdown_EN.png")
ax.set_title("Casistica dei tamponi in Italia (eccetto negativi)")
ax.set_ylabel("# tamponi")
ax.legend(["Terapia intensiva", "Ricoverati con sintomi", "Isolamento domiciliare", "Guariti", "Morti", "Negativi"])
ax.grid(axis="y")
fig.savefig("plots/Italy_Breakdown_IT.png")
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
df_relative = df[["data","tamponi", "terapia_intensiva", "ricoverati_con_sintomi", "isolamento_domiciliare","dimessi_guariti", "deceduti"]]
df_relative["terapia_intensiva"] = df_relative["terapia_intensiva"]/df_relative["tamponi"]
df_relative["ricoverati_con_sintomi"] = df_relative["ricoverati_con_sintomi"]/df_relative["tamponi"]
df_relative["isolamento_domiciliare"] = df_relative["isolamento_domiciliare"]/df_relative["tamponi"]
df_relative["dimessi_guariti"] = df_relative["dimessi_guariti"]/df_relative["tamponi"]
df_relative["deceduti"] = df_relative["deceduti"]/df_relative["tamponi"]
df_relative = df_relative.drop("tamponi", 1)
# ax = df_relative.plot.bar(x="data", stacked=True) borken
ax.bar(df_relative.data, df_relative.terapia_intensiva, color="tab:red")
ax.bar(df_relative.data, df_relative.ricoverati_con_sintomi, bottom=df_relative.terapia_intensiva, color="tab:orange")
ax.bar(df_relative.data, df_relative.isolamento_domiciliare, bottom=df_relative.terapia_intensiva + df_relative.ricoverati_con_sintomi, color="tab:blue")
ax.bar(df_relative.data, df_relative.dimessi_guariti, bottom=df_relative.terapia_intensiva + df_relative.ricoverati_con_sintomi + df_relative.isolamento_domiciliare, color="tab:green")
ax.bar(df_relative.data, df_relative.deceduti, bottom=df_relative.terapia_intensiva + df_relative.ricoverati_con_sintomi + df_relative.isolamento_domiciliare + df_relative.dimessi_guariti, color="tab:brown")
ax.xaxis_date()
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%d/%m"))
ax.set_title("Italian tests breakdown relative to total number of tests")
ax.set_ylabel("Fraction w.r.t. total tests")
ax.legend(["ICU cases", "Hospitalised w/ symptoms", "Quarantined at home", "Recoveries", "Deaths"])
ax.grid(axis="y")
fig.savefig("plots/Italy_Breakdown_Relative_EN.png")
ax.set_title("Casistica percentuale dei tamponi in Italia")
ax.set_ylabel("Frazione dei tamponi totali")
ax.legend(["Terapia intensiva", "Ricoverati con sintomi", "Isolamento domiciliare", "Guariti", "Morti"])
ax.grid(axis="y")
fig.savefig("plots/Italy_Breakdown_Relative_IT.png")