publiplots.resolve_param¶
- publiplots.resolve_param(key, value=None)[source]¶
Resolve a parameter value: return
valueif notNone, else the default forkey.This helper eliminates the repetitive
if value is None: value = defaultpattern in plot functions. Lookup checks publiplots custom parameters first (e.g."alpha","palette","subplots.axes_size"), then falls back tomatplotlib.pyplot.rcParams.- Parameters:
key (str) – Parameter name to look up when
valueisNone.value (Any, optional) – User-provided value. If not
None, it is returned unchanged.
- Returns:
Either the user-provided
value(if notNone) or the default forkey.- Return type:
Any
- Raises:
KeyError – If
valueisNoneandkeyis not defined in either publiplots or matplotlib rcParams.
Examples
Typical use inside a plotting function:
>>> from publiplots.themes.rcparams import resolve_param >>> def my_plot(color=None, alpha=None): ... color = resolve_param('color', color) ... alpha = resolve_param('alpha', alpha)
Explicit user value passes through unchanged:
>>> resolve_param('color', '#ff0000') '#ff0000'
Nonefalls back to the default:>>> resolve_param('color', None) '#5d83c3' >>> resolve_param('color') '#5d83c3'
See also
rcParamsUnified rcParams accessor for reading / writing defaults.