In [1]:
%config InlineBackend.figure_formats = ['svg']
import oscovida as ov
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, MONDAY, WeekdayLocator, DayLocator

ov.display_binder_link("tutorial-overview-plot_reproduction_number.ipynb")

Reproduction number

The forth and the fifth graphs returned by the overview function (see the overview and the explanation of the observables) show the R-value and the growth factor for COVID cases and deaths respectively. Here we show how it is created internally.

(Find more on reproduction number here.)

As earlier, we retrieve cases and deaths data, create an empty graph and populate the graph with the number calculated by a function plot_reproduction_number.

This function has the following parameters:

  • ax — an axis object;
  • series — the data source;
  • labels — a pair of strings: region label and identifier of cases or deaths;
  • color_g and color_R — two colors, here we use the scheme CN where N is a number digit, but one may use any colormap.
In [2]:
fig, ax = plt.subplots();    # create an empty graph
country = "US"
region = "California"

cases, deaths = ov.get_country_data(country, region)    # get actual data

# pass the data to the plotting function
ov.plot_reproduction_number(ax=ax, series=cases, labels=("USA: California","cases"), color_g="C0", color_R="C4");
ax.set_title("COVID Cases: R-value and Growth Factor");

# nicer X-axis formatting: put a tick every Monday
ax.get_xaxis().set_major_locator(DayLocator(bymonthday=(1))) 
ax.get_xaxis().set_major_formatter(DateFormatter('%d %b'))

Other tutorials

You can find more tutorials here.