MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _ensure_norm

Function _ensure_norm

lib/matplotlib/colorizer.py:760–782  ·  view source on GitHub ↗
(norm, n_components=1)

Source from the content-addressed store, hash-verified

758
759
760def _ensure_norm(norm, n_components=1):
761 if n_components == 1:
762 _api.check_isinstance((colors.Norm, str, None), norm=norm)
763 if norm is None:
764 norm = colors.Normalize()
765 elif isinstance(norm, str):
766 scale_cls = _api.getitem_checked(scale._scale_mapping, norm=norm)
767 return _auto_norm_from_scale(scale_cls)()
768 return norm
769 elif n_components > 1:
770 if not np.iterable(norm):
771 _api.check_isinstance((colors.MultiNorm, None, tuple), norm=norm)
772 if norm is None:
773 norm = colors.MultiNorm(['linear']*n_components)
774 else: # iterable, i.e. multiple strings or Normalize objects
775 norm = colors.MultiNorm(norm)
776 if isinstance(norm, colors.MultiNorm) and norm.n_components == n_components:
777 return norm
778 raise ValueError(
779 f"Invalid norm for multivariate colormap with {n_components} inputs")
780 else: # n_components == 0
781 raise ValueError(
782 "Invalid cmap. A colorizer object must have a cmap with `n_variates` >= 1")
783
784
785def _ensure_cmap(cmap, accept_multivariate=False):

Callers 1

normMethod · 0.85

Calls 1

_auto_norm_from_scaleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…