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()withhatch=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 thevalueslist.None— defaults toget_hatch_patterns()at the current mode.
reverse (bool, default
False) – Whether to reverse the pattern assignment order. Only applicable whenhatch_mapis a list orNone.mode (int, optional) – Pattern density mode (
1,2,3, or4). IfNone, uses the current global mode. Only applicable whenhatch_mapisNone.
- 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_hatchesResolve patterns without creating a mapping.
get_hatch_patternsGet patterns for a specific mode.