plot_population_impact_histogram
site_solutions.SolutionComparator.plot_population_impact_histogram(
matrix=None,
demand=None,
config_a=None,
config_b=None,
kind='kde',
bins=30,
bw_adjust=1,
colors=('#9fb8ad', '#1b7a5e'),
alpha=0.55,
figsize=(9, 5),
title='default',
caption=None,
ax=None,
)Overlaid before/after distribution of per-region travel cost – set_a (baseline) against set_b (candidate) – with reference lines and a legend annotating each side’s weighted mean and maximum travel cost.
The distributional counterpart to population_impact_summary()’s aggregate numbers and plot_population_impact_summary()’s bar charts: those answer “how many, how much” and “how did the average move”, this shows the whole shape of the shift – e.g. a long unaffected tail, or a bimodal split between a helped subgroup and everyone else, that a handful of summary numbers can collapse.
Weighted by demand where available, so the plotted mass represents people rather than regions – consistent with population_impact_summary()’s own demand-weighted framing. Falls back to unweighted (one region = one count) when no demand data is registered.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| matrix | str | Label of a secondary travel matrix registered via add_secondary_travel_matrix(). Plots that matrix’s own travel costs instead of the primary matrix’s. |
None |
| demand | str | Label of a secondary demand scenario registered via add_secondary_demand(). Weights the distribution by that scenario’s demand instead of the primary demand data. |
None |
| config_a | dict | Passed straight through to population_impact_summary(). |
None |
| config_b | dict | Passed straight through to population_impact_summary(). |
None |
| kind | (kde, hist) | “kde” draws a smoothed kernel density estimate for each side (via seaborn.kdeplot) – usually the easier way to compare the shape of two overlaid distributions, since it isn’t broken up into discrete bars that can visually clash between the two sides. “hist” draws a traditional binned histogram instead, which is more literal (bar height is an actual people/region count rather than a smoothed density) at the cost of being noisier and more prone to visual clutter where the two distributions overlap. |
"kde" |
| bins | int | Number of histogram bins. Only used when kind="hist"; the same bin edges (spanning both distributions) are used for both sides, so bar heights are directly comparable. |
30 |
| bw_adjust | float | Kernel bandwidth multiplier, forwarded to seaborn.kdeplot. Only used when kind="kde" – above 1 smooths the curve further, below 1 follows the data more closely (and more noisily). See seaborn.kdeplot’s own bw_adjust for details. |
1 |
| colors | (str, str) | (set_a colour, set_b colour), used for both the distributions and their matching mean/max reference lines. |
("#9fb8ad", "#1b7a5e") |
| alpha | float | Opacity of the filled distributions, so the overlap between the two sides stays visible. | 0.55 |
| figsize | tuple | Figure size, ignored if ax is given. |
(9, 5) |
| title | str | Plot title. If “default”, an automatic title is generated. | "default" |
| caption | str | Explanatory text shown below the chart, wrapped to fit. If None (the default) and kind="kde", a caption explaining that curve height is a relative share rather than a literal headcount is generated – a plain histogram’s bar heights need no such explanation, so kind="hist" adds none by default. Pass "" to suppress it, or a custom string to replace it. |
None |
| ax | matplotlib.axes.Axes | An existing Axes to draw into instead of creating a new figure – e.g. to embed this in a larger layout. | None |
Returns
| Name | Type | Description |
|---|---|---|
| (matplotlib.figure.Figure, matplotlib.axes.Axes) |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If kind is not “kde” or “hist”; if demand names an unregistered secondary demand scenario; or if set_a and set_b’s selected solutions were evaluated against different demand locations (see population_impact_summary()). |