Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

rcparams

rcparams

Package-wide defaults, in one validated mapping.

Every knob that used to live in a module-level DEFAULT_* dict is a key in rcParams, the way matplotlib’s own rcParams works, and for the same reason: a default that is worth having is worth being able to change once at the top of a notebook instead of at every call site.

import mnutils

mnutils.rcParams["image.cmap"] = "viridis"          # for the whole session
with mnutils.rc_context({"grid.panel_height": "30rem"}):
    ...                                             # ...or just for a block
mnutils.rcdefaults()                                # back to the built-ins

Three rules make this safe to rely on:

Attributes

NameDescription
rcParamsThe live parameter mapping every MNUtils function reads its defaults from.
rcParamsDefaultThe built-in defaults. Never mutated -- rcdefaults restores from here.
rc_presets

Classes

NameDescription
RcParamsA validated str -> value mapping of package defaults.

RcParams

rcparams.RcParams(mapping=None)

A validated str -> value mapping of package defaults.

Behaves like a dict, except that only keys in _VALIDATORS exist and every assignment goes through that key’s validator. Keys cannot be added or removed -- rcdefaults restores values, it never rebuilds the key set.

Methods

NameDescription
copyA detached RcParams holding the same values.
groupThe keys under prefix, with the prefix stripped.
copy
rcparams.RcParams.copy()

A detached RcParams holding the same values.

group
rcparams.RcParams.group(prefix)

The keys under prefix, with the prefix stripped.

rcParams.group("image.ax") gives {"xlabel": ..., "xticks": ...} -- the shape a matplotlib.axes.Axes.set call wants, which is why the axis defaults are stored as individual keys rather than as one opaque dict value.

Functions

NameDescription
rc_contextTemporarily override rcParams, restoring the previous values on exit.
rcdefaultsRestore every rcParam to its built-in default.
resolve_rcReturn value, or rcParams[key] when it is None.
validate_css_lengthAccept "30rem"/"400px"/"60vh", or a bare number read as rem.

rc_context

rcparams.rc_context(rc)

Temporarily override rcParams, restoring the previous values on exit.

Parameters

NameTypeDescriptionDefault
rcdictOverrides keyed by rcParam name, e.g. one of rc_presets. Names contain dots, so there is no keyword-argument form -- a mapping is the only way to spell them.required

Returns

NameTypeDescription
RcParamsThe live mapping, bound by as inside the block, so it can be inspected or further modified there. (NumPy convention would call this a Yields section; quartodoc’s renderer raises on one, so it is spelled Returns here.)

Examples

>>> with rc_context({"image.cmap": "gray"}):
...     pass

rcdefaults

rcparams.rcdefaults()

Restore every rcParam to its built-in default.

resolve_rc

rcparams.resolve_rc(value, key)

Return value, or rcParams[key] when it is None.

The one-liner behind every param: T | None = None signature in the package. Resolving in the body rather than in the signature is what makes an assignment to rcParams after import take effect at all.

validate_css_length

rcparams.validate_css_length(value)

Accept "30rem"/"400px"/"60vh", or a bare number read as rem.

Public because call-site overrides (plotting.images.display_images’s panel_height) bypass rcParams and so bypass its validation, while ending up in the same style attribute.