Border contrast

Settings and helpers of the border_contrast option of Choropleth and Category. See Borders between similar colours for how to use it.

class mappyng.BorderContrast(mode='fix', fill_ratio=1.5, stroke_ratio=2.0, light='#ffffff', dark='#222222', check_color='#ff00ff', width_factor=1.0)[source]

Bases: object

Settings of the border contrast check.

Passed as the border_contrast parameter of Choropleth and Category, or built from True, "fix", "check" or a dict of these fields.

Parameters:
  • mode (str) – "fix" (default) redraws the weak borders in a contrasting colour. "check" only reveals them: they are drawn thick in check_color and a warning reports how many there are and between which areas.

  • fill_ratio (float) – Two fills whose contrast ratio is below this value are considered alike (default 1.5): the colour change alone does not show the border.

  • stroke_ratio (float) – An outline whose contrast ratio with a fill is below this value does not show against it (default 2.0).

  • light, dark (str) – The two colours tried for a weak border. The one that contrasts most with the two fills is used, provided it improves on the current outline.

  • check_color (str) – Colour of the weak borders in "check" mode (default magenta).

  • width_factor (float) – Width of a redrawn border relative to the outline width (default 1.0).

__init__(mode='fix', fill_ratio=1.5, stroke_ratio=2.0, light='#ffffff', dark='#222222', check_color='#ff00ff', width_factor=1.0)
check_color: str = '#ff00ff'
dark: str = '#222222'
fill_ratio: float = 1.5
light: str = '#ffffff'
mode: str = 'fix'
stroke_ratio: float = 2.0
to_dict()[source]

Return the settings as a plain dict.

Return type:

dict[str, Any]

width_factor: float = 1.0
mappyng.border_contrast.parse_border_contrast(value)[source]

Turn a border_contrast parameter into a BorderContrast.

None and False disable the check; True and "fix" use the defaults; "check" reveals the weak borders; a dict sets any field.

Return type:

BorderContrast | None

mappyng.border_contrast.find_weak_borders(geometries, fills, stroke, cfg)[source]

Find the shared borders that the outline does not make visible.

Parameters:
  • geometries (GeoSeries or array of shapely geometries) – The areas, in the same order as fills.

  • fills (list of str) – Fill colour of each area.

  • stroke (str or None) – Outline colour of the areas (None or "none": no outline).

  • cfg (BorderContrast) – Thresholds and candidate colours.

Return type:

list[WeakBorder]

Returns:

list of WeakBorder – One entry per weak border between two touching areas that share a stretch of border of non-zero length. In "check" mode the colour is cfg.check_color.

class mappyng.border_contrast.WeakBorder(i, j, geometry, color)[source]

Bases: object

A border shared by two areas that needs a more visible colour.

Parameters:
  • i, j (int) – Positions of the two areas in the geometries given to find_weak_borders().

  • geometry (shapely geometry) – The shared border (line or multi-line).

  • color (str) – Colour proposed for it.

__init__(i, j, geometry, color)
color: str
geometry: Any
i: int
j: int