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.

Returns a dictionary that maps category names to specific hatch patterns, useful for categorical plots like publiplots.barplot() with hatch=True. Ensures consistent pattern assignment across multiple plots.

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

  • hatch_map (dict or list of str, optional) –

    Hatch pattern specification:

    • dict — explicit mapping from values to patterns; returned as-is.

    • list — patterns cycled through the values list.

    • None — defaults to get_hatch_patterns() at the current mode.

  • 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, 3, or 4). If None, uses the current global mode. Only applicable when hatch_map is None.

Returns:

dict of {str – Mapping from category values to hatch pattern strings.

Return type:

str}

Examples

Create a mapping for categories at mode 1:

>>> import publiplots as pp
>>> mapping = pp.resolve_hatch_map(values=['A', 'B', 'C', 'D'], mode=1)
>>> mapping['A']
''
>>> mapping['B']
'/'

Use custom patterns cycled through values:

>>> mapping = pp.resolve_hatch_map(
...     values=['cat', 'dog', 'bird'],
...     hatch_map=['///', '|||', 'xxx'],
... )

Pass an explicit mapping (returned unchanged):

>>> mapping = pp.resolve_hatch_map(
...     values=['A', 'B'],
...     hatch_map={'A': '///', 'B': '|||'},
... )
>>> mapping
{'A': '///', 'B': '|||'}

Use dense patterns:

>>> mapping = pp.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.