diff --git a/basics.py b/basics.py new file mode 100644 index 0000000..f3b31ad --- /dev/null +++ b/basics.py @@ -0,0 +1,38 @@ +""" +Plot total cases of countries over time on log scale +""" +import matplotlib.pyplot as pp + +def plot(data, countries): + + for loc in data: + if loc not in countries: + continue + time, new_cases, new_deaths, total_cases, total_deaths = data[loc] + + # total cases + pp.figure("total_cases") + pp.plot(time, total_cases, label=f"{loc}") + + # total deaths + pp.figure("total_deaths") + pp.plot(time, total_deaths, label=f"{loc}") + + # new cases + pp.figure("new_cases") + pp.plot(time, new_cases, label=f"{loc}") + + # new deaths + pp.figure("new_deaths") + pp.plot(time, new_deaths, label=f"{loc}") + + for name in ["total_cases", "total_deaths", "new_cases", "new_deaths"]: + postprocess(name) + +def postprocess(name): + pp.yscale("log") + pp.xticks(rotation=90) + pp.legend(frameon=False) + pp.tight_layout() + + pp.savefig(f"{name}.png") diff --git a/coronavis.py b/coronavis.py index 70a1c81..168e652 100644 --- a/coronavis.py +++ b/coronavis.py @@ -14,7 +14,7 @@ sys.path.append(".") # countries of interest countries = ["Germany", "Italy", "Spain", "Denmark", "China", "Japan", "South Korea", "Iran", "Belgium", "World"] # enabled plots -plots = ["total_cases", "death_per_case", "normalized_to_first_death"] +plots = ["basics", "death_per_case", "normalized_to_first_death"] ### def get_data(): """fetch data from remote, cache locally and reorganize internal data diff --git a/total_cases.py b/total_cases.py deleted file mode 100644 index 4d1eeb0..0000000 --- a/total_cases.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Plot total cases of countries over time on log scale -""" -import matplotlib.pyplot as pp -name="total_cases" - -def plot(data, countries): - - for loc in data: - if loc not in countries: - continue - time, new_cases, new_deaths, total_cases, total_deaths = data[loc] - - # total cases - pp.figure(name) - pp.plot(time, total_cases, label=f"{loc}") - - pp.yscale("log") - pp.xticks(rotation=90) - pp.legend(frameon=False) - pp.tight_layout() - - pp.savefig(name+".png")