Plots

The plots module in seirmo includes a number of visualisation classes.

Overview:

class seirmo.plots.IncidenceNumberPlot[source]

A figure class that illustrates the incidence number time series as a bar plot over time.

add_data(data, time_key='Time', inc_key='Incidence Number')[source]

Add a bar plot trace for the given incidence number data in the figure

Parameters:
  • data – A pandas.DataFrame including two columns, one being time points, the other being incidence number.

  • time_key – Key label of the DataFrame which specifies the time points. Defaults to ‘Time’.

  • inc_key – Key label of the DataFrame which specifies the incididence number. Defaults to ‘Incidence Number’.

add_simulation(data, time_key='Time', inc_key='Incidence Number')[source]

Add a bar plot trace for the simulated incidence numbers in the figure

Parameters:
  • data – A pandas.DataFrame including two columns, one being time points, the other being incidence number.

  • time_key – Key label of the DataFrame which specifies the time points. Defaults to ‘Time’.

  • inc_key – Key label of the DataFrame which specifies the incididence number. Defaults to ‘Incidence Number’.

class seirmo.plots.CompartmentPlot[source]

A figure class that illustrates the compartment number time series as a line plot over time.

add_simulation(data, time_key='Time', compartment_keys=['Susceptible', 'Exposed', 'Infectious', 'Recovered'])[source]

Add line plot traces for the simulated compartment numbers in the figure

Parameters:
  • data – A pandas.DataFrame including columns for time points and compartment numbers

  • time_key – Key label of the DataFrame which specifies the time points. Defaults to ‘Time’.

  • compartment_keys – The list of key labels of the DataFrame which specify the compartments. Defaults to [‘Susceptible’, ‘Exposed’, ‘Infectious’, ‘Recovered’].

class seirmo.plots.SubplotFigure[source]

A class that creates a figure consisting of subplots for IncidenceNumberPlot and CompartmentPlot.

add_data(data, time_key='Time', inc_key='Incidence Number')[source]

Add a bar plot trace for the given incidence number data in the bar subplot

Parameters:
  • data – A pandas.DataFrame including two columns, one being time points, the other being incidence number.

  • time_key – Key label of the DataFrame which specifies the time points. Defaults to ‘Time’.

  • inc_key – Key label of the DataFrame which specifies the incididence number. Defaults to ‘Incidence Number’.

add_simulation(data, time_key='Time', inc_key='Incidence Number', compartment_keys=['Susceptible', 'Exposed', 'Infectious', 'Recovered'])[source]

Add a bar plot trace for the simulated incidence numbers in the first subplot, and add line plot traces for the simulated compartment numbers in the second subplot.

Parameters:
  • data – A pandas.DataFrame including columns for time points, incidence number, compartment numbers

  • time_key – Key label of the DataFrame which specifies the time points. Defaults to ‘Time’.

  • inc_key – Key label of the DataFrame which specifies the incididence number. Defaults to ‘Incidence Number’.

  • compartment_keys – The list of key labels of the DataFrame which specify the compartments. Defaults to [‘Susceptible’, ‘Exposed’, ‘Infectious’, ‘Recovered’].

get_subplots()[source]

Get the traces and layout into the subplots

show()[source]

Display the figure

class seirmo.plots.ConfigurablePlotter[source]

A figure class that visualises the population of each compartment over time Configurable to plot multiple subplots in one figure, with customised labels or colours Implements addfill() method to plot a shaded region between two datasets (I.e. when plotting confidence intervals)

add_data_to_plot(times: ndarray, data_array: ndarray, position: list = [0, 0], xlabel: str = 'time', ylabels: list = [], colours: list = [], new_axis=False)[source]

Main code to add new data into the plot

Params::

times: np.ndarray, independent x- variable

Params::

data_array: np.ndarray, multiple dependent y- variables Data should has one row per timestep, and one column for each dependent variable

Params::

position: list of integers, gives index of subplot to use

Params::

xlabel: str

Params::

ylabel: list of strings (a single string is also accepted)

Params::

colours: list of valid colour specifiers (ie strings or rgb tuples)

Params::

new_axis: boolean, set to true if data should be plotted on a second x axis

add_fill(times: ndarray, ymin: ndarray, ymax: ndarray, position: list = [0, 0], xlabel: str = 'time', ylabel: str = 'number of people', colour: str = ['b'], alpha: float = 0.2)[source]

Code to plot shaded region between two datasets

Params::

times: np.ndarray, independent x- variable

Params::

ymin: np.ndarray, dependent y- variables

Params::

ymin: np.ndarray, comparison y- variables

Params::

position: list of integers, gives index of subplot to use

Params::

xlabel: str

Params::

ylabel: list of strings

Params::

colour: any valid colour specifier

Params::

alpha: float, indicate transparency of filled region

N.B While it is recommended that y_min should be the (generally) smaller dataset for readability, this is not required, and the datasets may cross (i.e. y_min may be larger in sections)

begin(subplots_rows: int = 1, subplots_columns: int = 1)[source]

Begins creating a figure, with given number of subfigures Replaces init class so object can be reused