plot_n_best_combinations
site.SiteSolutionSet.plot_n_best_combinations(
n_best=10,
rank_on=None,
title=None,
subplot_title='default',
show_all_locations=True,
plot_site_allocation=False,
plot_regions_not_meeting_threshold=False,
cmap=None,
chosen_site_colour='black',
unchosen_site_colour='grey',
n_cols=None,
n_rows=None,
fig_size_multiplier=6,
)Plot maps for the top-performing site combinations.
This method generates a grid of subplots visualising the spatial performance of the top n_best solutions. Each subplot represents a single solution, showing either travel costs, site allocations, or coverage relative to a threshold. Candidate site locations can also be overlaid.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| n_best | int | Number of top solutions to plot. If greater than the number of available solutions, all solutions are plotted. | 10 |
| rank_on | str | Column name used to rank solutions. If provided, solutions are sorted in ascending order and the top n_best are selected. If None, the existing order of solution_df is used. |
None |
| title | str or None | Title applied to each subplot. If provided, overrides subplot_title. If None, subplot titles are controlled by subplot_title. |
None |
| subplot_title | str or None | Title for each subplot. If “default”, an automatic title is generated based on the objective and solution metrics. If a string is provided, it may be evaluated using _safe_evaluate with access to the selected solution. If None, no subplot titles are shown. |
"default" |
| show_all_locations | bool | If True, plots all candidate site locations in addition to the selected sites. | True |
| plot_site_allocation | bool | If True, regions are coloured by the assigned (nearest) site. Overrides other colouring options. | False |
| plot_regions_not_meeting_threshold | bool | If True, regions are coloured based on whether they fall within the coverage threshold. Overrides default cost-based colouring. | False |
| cmap | str or matplotlib colormap | Colormap used for plotting. If None, a default is chosen: - Sequential colormap (e.g., “Blues”) for cost-based plots - Qualitative colormap (e.g., “Set2”) for site allocation plots | None |
| chosen_site_colour | str | Colour used to plot selected site locations. | "black" |
| unchosen_site_colour | str | Colour used to plot unselected candidate site locations. | "grey" |
| n_cols | int | Number of columns in the subplot grid. If None, determined automatically. | None |
| n_rows | int | Number of rows in the subplot grid. If None, determined automatically. | None |
| fig_size_multiplier | Factor to adjust overall plot size | 6 |
Returns
| Name | Type | Description |
|---|---|---|
| fig | matplotlib.figure.Figure | The matplotlib Figure object containing all subplots. |
| ax | matplotlib.axes.Axes | The last Axes object created in the plotting loop. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the region geometry layer has not been initialised in the site_problem instance. |
Notes
The method requires a valid region_geometry_layer to be present in site_problem. This should be added prior to calling this method.
Subplots are arranged in a grid determined by n_best, n_cols, and n_rows. If neither n_cols nor n_rows is provided, a default layout with up to 5 columns is used.
Depending on the flags provided, regions are coloured by: - “min_cost” (default): travel time/distance to the nearest site - “selected_site”: assigned site (categorical) - “within_threshold”: whether the region meets the coverage threshold
When plotting cost-based maps, a consistent global colour scale is applied across all subplots.
When plotting categorical site allocations, a consistent colour mapping is constructed across all subplots to ensure comparability.
A shared legend or colourbar is added to the figure depending on the plotting mode.
The method assumes that lower values of the ranking metric correspond to better solutions.