from
matplotlib
import
pyplot as plt
import
requests
def
Plot(country):
req.raise_for_status()
cf
=
req.text.split(
'\n'
)
for
i
in
range
(
len
(cf)):
cf[i]
=
cf[i].split(
', '
)
dates
=
[]
total
=
[]
total_w
=
[]
deaths
=
[]
deaths_w
=
[]
l
=
[]
f
=
0
for
i
in
range
(
len
(cf)
-
1
):
l
=
cf[i]
c
=
l[
1
]
if
c
=
=
country:
f
=
1
dates.append(l[
0
][
5
:])
total.append(
int
(l[
4
]))
deaths.append(
int
(l[
5
]))
if
c
=
=
'World'
:
total_w.append(
int
(l[
4
]))
deaths_w.append(
int
(l[
5
]))
if
f
=
=
0
:
print
(
"Invalid country name."
)
return
total_ax
=
plt.subplot(
2
,
2
,
1
)
total_ax.set_title(country
+
' (Total Cases)'
)
total_ax.plot(dates[
-
20
:], total[
-
20
:])
total_ax.bar(dates[
-
20
:], total[
-
20
:], alpha
=
0.5
)
total_ax.set_xlabel(
"Date"
)
plt.xticks(rotation
=
45
)
death_ax
=
plt.subplot(
2
,
2
,
2
)
death_ax.set_title(country
+
' (Total Deaths)'
)
death_ax.plot(dates[
-
20
:], deaths[
-
20
:], color
=
'red'
)
death_ax.bar(dates[
-
20
:], deaths[
-
20
:], color
=
'red'
, alpha
=
0.5
)
death_ax.set_xlabel(
"Date"
)
plt.xticks(rotation
=
45
)
total_w_ax
=
plt.subplot(
2
,
2
,
3
)
total_w_ax.set_title(
'World (Total Cases)'
)
total_w_ax.plot(dates[
-
20
:], total_w[
-
20
:])
total_w_ax.bar(dates[
-
20
:], total_w[
-
20
:], alpha
=
0.5
)
total_w_ax.set_xlabel(
"Date"
)
plt.xticks(rotation
=
45
)
death_w_ax
=
plt.subplot(
2
,
2
,
4
)
death_w_ax.set_title(
'World (Total Deaths)'
)
death_w_ax.plot(dates[
-
20
:], deaths_w[
-
20
:], color
=
'red'
)
death_w_ax.bar(dates[
-
20
:], deaths_w[
-
20
:], color
=
'red'
, alpha
=
0.5
)
death_w_ax.set_xlabel(
"Date"
)
plt.xticks(rotation
=
45
)
plt.tight_layout()
print
(
"Enter country name..."
)
country
=
input
().title()
Plot(country)
plt.show()