synthpops.plotting module¶
This module plots the age-specific contact matrix in different settings.
-
synthpops.plotting.
calculate_contact_matrix
(population, density_or_frequency='density', setting_code='H')¶ Calculate the symmetric age-specific contact matrix from the connections for all people in the population. density_or_frequency sets the type of contact matrix calculated.
When density_or_frequency is set to ‘frequency’ each person is assumed to have a fixed amount of contact with others they are connected to in a setting so each person will split their contact amount equally among their connections. This means that if a person has links to 4 other individuals then 1/4 will be added to the matrix element matrix[age_i][age_j] for each link, where age_i is the age of the individual and age_j is the age of the contact. This follows the mass action principle such that increased density or number of people a person is in contact with leads to decreased per-link or connection contact rate.
When density_or_frequency is set to ‘density’ the amount of contact each person has with others scales with the number of people they are connected to. This means that a person with connections to 4 individuals has a higher total contact rate than a person with connection to 3 individuals. For this definition if a person has links to 4 other individuals then 1 will be added to the matrix element matrix[age_i][age_j] for each contact. This follows the ‘pseudo’mass action principle such that the per-link or connection contact rate is constant.
- Parameters
population (dict) – A dictionary of a population with attributes.
density_or_frequency (str) – option for the type of contact matrix calculated.
setting_code (str) – name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other, and ‘lTCF’ for long term care facilities
- Returns
Symmetric age specific contact matrix.
-
synthpops.plotting.
plot_contacts
(population, setting_code='H', aggregate_flag=True, logcolors_flag=True, density_or_frequency='density', cmap='cmr.freeze_r', fontsize=16, rotation=50, title_prefix=None, fig=None, ax=None, do_show=True)¶ Plot the age mixing matrix for a specific setting.
TODO: rename setting_code to layer
- Parameters
population (dict) – population to be plotted, if None, code will generate it
setting_code (str) – name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other
aggregate_flag (bool) – If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix.
logcolors_flag (bool) – If True, plot heatmap in logscale
density_or_frequency (str) – If ‘density’, then each contact counts for 1/(group size -1) of a person’s contact in a group, elif ‘frequency’ then count each contact. This means that more people in a group leads to higher rates of contact/exposure.
cmap (str or matplotlib colormap) – colormap
fontsize (int) – base font size
rotation (int) – rotation for x axis labels
title_prefix (str) – optional title prefix for the figure
fig (Figure) – if supplied, use this figure instead of generating one
ax (Axes) – if supplied, use these axes instead of generating one
do_show (bool) – whether to show the plot
- Returns
A fig object.