plot_best_combination
site.SiteSolutionSet.plot_best_combination(
rank_on=None,
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',
legend_loc='upper right',
)Plot a map of the best-performing site combination.
This method visualises the spatial performance of the best solution in the solution set, including travel costs, site allocations, or coverage relative to a threshold. Regions are coloured according to the selected metric, and candidate site locations can be overlaid.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| rank_on | str | Column name used to rank solutions. If provided, the solution with the lowest value in this column is selected. If None, the first row of solution_df is used. |
None |
| title | str or None | Title for the plot. 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 title is set. |
"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 (“Blues”) for cost-based plots - Qualitative colormap (“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" |
| legend_loc | Adjust position of the legend within the main plot. Accepts standard matplotlib positioning strings. | 'upper right' |
Returns
| Name | Type | Description |
|---|---|---|
| matplotlib.axes.Axes | The matplotlib Axes object containing the generated plot. |
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.
The plot is generated using GeoPandas and includes a basemap via contextily.add_basemap.
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 site locations, only GeoPandas-based candidate sites are currently supported.
Titles are dynamically generated based on the objective type and may include metrics such as weighted/unweighted averages, maximum cost, and coverage proportion.
The method assumes that lower values of the ranking metric correspond to better solutions.