publiplots.resolve_hatch_map

publiplots.resolve_hatch_map(values=None, hatch_map=None, reverse=False, mode=None)[source]

Create a mapping from category values to hatch patterns.

This function creates a dictionary that maps category names to specific hatch patterns, which is useful for categorical plots like barplots. It ensures consistent pattern assignment across multiple plots.

Parameters:
  • values (list of str, optional) – List of category values to map to patterns. If None, returns empty dict.

  • hatch_map (dict or list, optional) – Hatch pattern specification: - dict: Explicit mapping from values to patterns (returned as-is) - list: List of patterns to cycle through for values - None: Uses default patterns from get_hatch_patterns()

  • reverse (bool, default=False) – Whether to reverse the pattern assignment order. Only applicable when hatch_map is a list or None.

  • mode (int, optional) – Pattern density mode (1, 2, or 3). If None, uses current global mode. Only applicable when hatch_map is None.

Returns:

Mapping from category values to hatch pattern strings.

Return type:

Dict[str, str]

Examples

Create mapping for categories: >>> categories = [‘A’, ‘B’, ‘C’, ‘D’] >>> mapping = resolve_hatch_map(values=categories) >>> mapping[‘A’] ‘’ >>> mapping[‘B’] ‘///’

Use custom patterns: >>> mapping = resolve_hatch_map( … values=[‘cat’, ‘dog’, ‘bird’], … hatch_map=[‘///’, ‘|||’, ‘xxx’] … )

Use explicit mapping: >>> mapping = resolve_hatch_map( … values=[‘A’, ‘B’], … hatch_map={‘A’: ‘///’, ‘B’: ‘|||’} … ) >>> mapping {‘A’: ‘///’, ‘B’: ‘|||’}

Use dense patterns: >>> mapping = resolve_hatch_map(values=[‘A’, ‘B’, ‘C’], mode=3)

See also

resolve_hatches

Resolve patterns without creating a mapping

get_hatch_patterns

Get patterns for a specific mode