publiplots.resolve_param

publiplots.resolve_param(key, value=None)[source]

Resolve a parameter value: return value if not None, else the default for key.

This helper eliminates the repetitive if value is None: value = default pattern in plot functions. Lookup checks publiplots custom parameters first (e.g. "alpha", "palette", "subplots.axes_size"), then falls back to matplotlib.pyplot.rcParams.

Parameters:
  • key (str) – Parameter name to look up when value is None.

  • value (Any, optional) – User-provided value. If not None, it is returned unchanged.

Returns:

Either the user-provided value (if not None) or the default for key.

Return type:

Any

Raises:

KeyError – If value is None and key is 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'

None falls back to the default:

>>> resolve_param('color', None)
'#5d83c3'
>>> resolve_param('color')
'#5d83c3'

See also

rcParams

Unified rcParams accessor for reading / writing defaults.