plotting

plotting

Standard plots used in calibrations and analyses

Classes

Name Description
Config Configuration for plots

Config

plotting.Config()

Configuration for plots

Methods

Name Description
get_figs_directory Get the current figures directory.
load_validation_data Load validation data for the specified country or region using DataLoader.
set_figs_directory Set the figures directory and ensure it exists.
get_figs_directory
plotting.Config.get_figs_directory()

Get the current figures directory.

load_validation_data
plotting.Config.load_validation_data(location, val_data_mapping=None, keys=None)

Load validation data for the specified country or region using DataLoader.

Parameters
Name Type Description Default
location str The name of the location folder (region or country). required
val_data_mapping dict Custom mapping of validation data keys to filenames. Defaults to default_val_data_mapping. None
keys str or list of str Specific metric(s) to load (e.g., ‘asfr’ or [‘asfr’, ‘tfr’]). None
Returns
Name Type Description
sc.objdict: Loaded validation data (either full or partial dict with requested keys).
set_figs_directory
plotting.Config.set_figs_directory(new_directory)

Set the figures directory and ensure it exists.

Functions

Name Description
compute_rmse Compute mean-normalized Root Mean Squared Error (RMSE) between model output and real data.
plot_afb Plot age at first birth: model vs survey data
plot_ageparity Plot an age-parity distribution for model vs data
plot_all Plots all the figures above besides empowerment plots
plot_asfr Plots age-specific fertility rate
plot_birth_spacing Plot birth space and age at first birth for model vs data
plot_calib Plots the commonly used plots for calibration
plot_cpr Plot contraceptive prevalence rate for model vs data
plot_cpr_by_age Plot CPR by age.
plot_education Plot years of educational attainment between model and data
plot_method_mix Plots both dichotomous method data_use and non-data_use and contraceptive mix
plot_method_use Plot contraceptive method use for model vs data
plot_paid_work Plot rates of paid employment between model and data; only used for empowerment analyses
plot_pop_growth Plot annual population growth rate for model vs data
plot_tfr Plot total fertility rate for model vs data
pop_growth_rate Calculates growth rate as a time series to help compare model to data
save_figure Helper function to save a figure if saving is enabled.

compute_rmse

plotting.compute_rmse(model_vals, data_vals)

Compute mean-normalized Root Mean Squared Error (RMSE) between model output and real data.

Normalization is done by dividing RMSE by the mean of the data values.

:param model_vals: List or numpy array of model-generated values :param data_vals: List or numpy array of real-world data values :return: Normalized RMSE (unitless)

plot_afb

plotting.plot_afb(sim, ax=None, legend_kwargs={})

Plot age at first birth: model vs survey data

plot_ageparity

plotting.plot_ageparity(sim, ax=None)

Plot an age-parity distribution for model vs data

plot_all

plotting.plot_all(sim)

Plots all the figures above besides empowerment plots

plot_asfr

plotting.plot_asfr(sim, ax=None)

Plots age-specific fertility rate

plot_birth_spacing

plotting.plot_birth_spacing(
    sim,
    ax=None,
    legend_kwargs={},
    min_age=15,
    max_age=50,
)

Plot birth space and age at first birth for model vs data

plot_calib

plotting.plot_calib(sim, single_fig=False, fig_kwargs=None, legend_kwargs=None)

Plots the commonly used plots for calibration

plot_cpr

plotting.plot_cpr(
    sim,
    start_year=None,
    end_year=None,
    ax=None,
    legend_kwargs={},
)

Plot contraceptive prevalence rate for model vs data

plot_cpr_by_age

plotting.plot_cpr_by_age(sim)

Plot CPR by age. Note: This plot can only be run if the sim used the analyzer ‘cpr_by_age’

plot_education

plotting.plot_education(sim)

Plot years of educational attainment between model and data

plot_method_mix

plotting.plot_method_mix(sim, ax=None, legend_kwargs={})

Plots both dichotomous method data_use and non-data_use and contraceptive mix

plot_method_use

plotting.plot_method_use(sim, ax=None, legend_kwargs={})

Plot contraceptive method use for model vs data

plot_paid_work

plotting.plot_paid_work(sim, data_employment)

Plot rates of paid employment between model and data; only used for empowerment analyses

plot_pop_growth

plotting.plot_pop_growth(sim, ax=None, legend_kwargs={})

Plot annual population growth rate for model vs data

plot_tfr

plotting.plot_tfr(
    sim,
    ax=None,
    start_year=None,
    stop_year=2020,
    legend_kwargs={},
)

Plot total fertility rate for model vs data

pop_growth_rate

plotting.pop_growth_rate(years, population)

Calculates growth rate as a time series to help compare model to data

save_figure

plotting.save_figure(filename)

Helper function to save a figure if saving is enabled.