In [1]:
%config InlineBackend.figure_formats = ['svg']
import oscovida as ov
In [2]:
ov.display_binder_link("tutorial-overview-plot_time_step.ipynb")

Total cumulative numbers

The first graph returned by the overview function (see the overview and the explanation of the observables) shows the cumulative numbers for COVID cases and deaths. Here we show how it is created internally.

Firstly, we import the plotting framework and some special functions:

In [3]:
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, FuncFormatter, FixedLocator
from matplotlib.dates import DateFormatter, MONDAY, WeekdayLocator

We will need an empty Matplotlib graph object to pass onto the plotting functions.

In [4]:
fig1, ax1 = plt.subplots();

Now let's add some data to our empty graph

In [5]:
country = "Iran"
weeks = 30
cases, deaths = ov.get_country_data(country)

Now we populate the empty plot we have with the data. We call the ploting function twice with two different series of data:

In [6]:
ov.plot_time_step(ax=ax1, series=cases)   # add cases to the graph
ov.plot_time_step(ax=ax1, series=deaths)  # add deaths to the graph
ax1.set_title("Total numbers, log scale")
ax1.legend()
ax1
fig1
Out[6]:

Additionaly, one may turn off the logarithmic scale with logscale=False and pick another line style:

In [7]:
fig2, ax2 = plt.subplots();
ov.plot_time_step(ax=ax2, series=cases, style='*', logscale=False)   # add cases to the graph
ov.plot_time_step(ax=ax2, series=deaths, style='--', logscale=False)  # add deaths to the graph
ax2.set_title("Total numbers, linear scale")
ax2.legend();

Other tutorials

You can find more tutorials here.