all basic plots
This commit is contained in:
32
basics.py
32
basics.py
@@ -5,34 +5,32 @@ import matplotlib.pyplot as pp
|
|||||||
|
|
||||||
def plot(data, countries):
|
def plot(data, countries):
|
||||||
|
|
||||||
|
tcp, tc = pp.subplots()
|
||||||
|
tdp, td = pp.subplots()
|
||||||
|
ncp, nc = pp.subplots()
|
||||||
|
ndp, nd = pp.subplots()
|
||||||
for loc in data:
|
for loc in data:
|
||||||
if loc not in countries:
|
if loc not in countries:
|
||||||
continue
|
continue
|
||||||
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
|
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
|
||||||
|
|
||||||
# total cases
|
# total cases
|
||||||
pp.figure("total_cases")
|
tc.plot(time, total_cases, label=f"{loc}")
|
||||||
pp.plot(time, total_cases, label=f"{loc}")
|
|
||||||
|
|
||||||
# total deaths
|
# total deaths
|
||||||
pp.figure("total_deaths")
|
td.plot(time, total_deaths, label=f"{loc}")
|
||||||
pp.plot(time, total_deaths, label=f"{loc}")
|
|
||||||
|
|
||||||
# new cases
|
# new cases
|
||||||
pp.figure("new_cases")
|
nc.plot(time, new_cases, label=f"{loc}")
|
||||||
pp.plot(time, new_cases, label=f"{loc}")
|
|
||||||
|
|
||||||
# new deaths
|
# new deaths
|
||||||
pp.figure("new_deaths")
|
nd.plot(time, new_deaths, label=f"{loc}")
|
||||||
pp.plot(time, new_deaths, label=f"{loc}")
|
|
||||||
|
|
||||||
for name in ["total_cases", "total_deaths", "new_cases", "new_deaths"]:
|
for ax, fig, name in [(tc, tcp, "total_cases"), (td, tdp, "total_deaths"), (nc, ncp, "new_cases"), (nd, ndp, "new_deaths")]:
|
||||||
postprocess(name)
|
ax.set_yscale("log")
|
||||||
|
for tick in ax.get_xticklabels():
|
||||||
|
tick.set_rotation(45)
|
||||||
|
ax.legend(frameon=False)
|
||||||
|
fig.tight_layout()
|
||||||
|
|
||||||
def postprocess(name):
|
fig.savefig(name+".png")
|
||||||
pp.yscale("log")
|
|
||||||
pp.xticks(rotation=90)
|
|
||||||
pp.legend(frameon=False)
|
|
||||||
pp.tight_layout()
|
|
||||||
|
|
||||||
pp.savefig(f"{name}.png")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user