plotting

plotting

HPVsim plotting helpers built on matplotlib + Starsim’s built-in plotting.

Functions

Name Description
plot_age_causal_infection Histograms of age at causal infection / CIN2+ / cancer and the precin /
plot_age_pyramid Back-to-back male/female age-pyramid bars from an age_pyramid analyzer.
plot_by_age Plot an by_age result as a series per year over age bins.
plot_by_genotype Overlay a per-genotype result across genotypes over time.
plot_calibration Data-vs-fit plot for a run hpv.Calibration.
plot_dalys Stacked YLL/YLD over the analyzer’s year axis.
plot_intervention_impact Compare a baseline vs an intervention scenario.
plot_sim HPV-specific summary figure.
plot_type_distribution Bar chart of each genotype’s share of key at a given year.

plot_age_causal_infection

plotting.plot_age_causal_infection(aci, fig=None)

Histograms of age at causal infection / CIN2+ / cancer and the precin / cin / total dwell-time distributions (weight-aware).

plot_age_pyramid

plotting.plot_age_pyramid(age_pyramid_az, date=None, fig=None)

Back-to-back male/female age-pyramid bars from an age_pyramid analyzer.

plot_by_age

plotting.plot_by_age(
    age_results,
    key,
    years=None,
    kind='line',
    fig=None,
    **kwargs,
)

Plot an by_age result as a series per year over age bins.

Parameters

Name Type Description Default
age_results a run hpv.by_age analyzer. required
key a result name recorded by that analyzer (e.g. ‘cancers’). required
years scalar/list of years to plot; default = all recorded years. None
kind ‘line’ or ‘bar’. 'line'

plot_by_genotype

plotting.plot_by_genotype(
    sim,
    key='cum_cancers',
    normalize=False,
    fig=None,
    **kwargs,
)

Overlay a per-genotype result across genotypes over time.

Lines (one per genotype) by default; stacked areas when normalize=True (per-year genotype shares summing to 1).

plot_calibration

plotting.plot_calibration(calib, top_n=50, fig=None, ncols=None)

Data-vs-fit plot for a run hpv.Calibration.

Auto-inspects calib.eval_kw['data'] and renders one panel per (scope, name) target group, overlaying a top-top_n-trial model ribbon / box on the observed data.

Panel layout by scope

  • all_hpv.<name>.<bin> age-stratified: line + 95% PI band vs. data scatter, x = age bins.
  • all_hpv.<name> scalar: timeseries if multi-year, else an errorbar point.
  • by_genotype.<name>.<g> box plot per genotype vs. data markers.

Parameters

Name Type Description Default
calib run hpv.Calibration. required
top_n int number of best-mismatch trials to re-run for the ribbon (default 50). Clamped to available trials. 50
fig matplotlib Figure to draw into (default: new). None
ncols int grid ncols (default: min(n_panels, 3)). None

plot_dalys

plotting.plot_dalys(dal, fig=None)

Stacked YLL/YLD over the analyzer’s year axis.

plot_intervention_impact

plotting.plot_intervention_impact(
    baseline,
    scenario,
    key='cum_cancers',
    labels=('baseline', 'scenario'),
    fig=None,
)

Compare a baseline vs an intervention scenario.

baseline/scenario are each an ss.Sim or ss.MultiSim. Top panel: median key trajectory per arm (10/90 band when a MultiSim); bottom panel: averted = baseline_median - scenario_median. Raises if the two arms have different timevecs.

plot_sim

plotting.plot_sim(sim, which='default', fig=None, **kwargs)

HPV-specific summary figure.

which=‘default’: 4-panel canonical figure (cumulative cancers over time, prevalence by age, cancers by age, genotype distribution). Requires an by_age analyzer recording a prevalence key and ‘cancers’. Any other value (e.g. ‘all’) delegates to ss.Sim.plot. fig is honored in both modes (a new figure is created if None). Pass a fresh/empty figure: multi-panel helpers add subplots rather than reusing existing axes.

plot_type_distribution

plotting.plot_type_distribution(
    source,
    year=None,
    key='cum_cancers',
    fig=None,
    **kwargs,
)

Bar chart of each genotype’s share of key at a given year.

source is a run hpv.Sim. Delegates to results_by_genotype. For a year with zero cancers the normalized shares are all 0 (not 1).