age_histogram#

class age_histogram(days=None, states=None, edges=None, datafile=None, sim=None, die=True, **kwargs)[source]#

Bases: Analyzer

Calculate statistics across age bins, including histogram plotting functionality.

Parameters:
  • days (list) – list of ints/strings/date objects, the days on which to calculate the histograms (default: last day)

  • states (list) – which states of people to record (default: exposed, tested, diagnosed, dead)

  • edges (list) – edges of age bins to use (default: 10 year bins from 0 to 100)

  • datafile (str) – the name of the data file to load in for comparison, or a dataframe of data (optional)

  • sim (Sim) – only used if the analyzer is being used after a sim has already been run

  • die (bool) – whether to raise an exception if dates are not found (default true)

  • kwargs (dict) – passed to Analyzer()

Examples:

sim = cv.Sim(analyzers=cv.age_histogram())
sim.run()

agehist = sim.get_analyzer()
agehist = cv.age_histogram(sim=sim) # Alternate method
agehist.plot()

Methods

from_sim(sim)[source]#

Create an age histogram from an already run sim

get(key=None)[source]#

Retrieve a specific histogram from the given key (int, str, or date)

compute_windows()[source]#

Convert cumulative histograms to windows

plot(windows=False, width=0.8, color='#F8A493', fig_args=None, axis_args=None, data_args=None, **kwargs)[source]#

Simple method for plotting the histograms.

Parameters:
  • windows (bool) – whether to plot windows instead of cumulative counts

  • width (float) – width of bars

  • color (hex or rgb) – the color of the bars

  • fig_args (dict) – passed to pl.figure()

  • axis_args (dict) – passed to pl.subplots_adjust()

  • data_args (dict) – ‘width’, ‘color’, and ‘offset’ arguments for the data

  • kwargs (dict) – passed to cv.options.with_style(); see that function for choices