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

Function _ensure_cmap

lib/matplotlib/colorizer.py:785–832  ·  view source on GitHub ↗

Ensure that we have a `.Colormap` object. For internal use to preserve type stability of errors. Parameters ---------- cmap : None, str, Colormap - if a `~matplotlib.colors.Colormap`, `~matplotlib.colors.MultivarColormap` or `~matplotlib.colors.Biv

(cmap, accept_multivariate=False)

Source from the content-addressed store, hash-verified

783
784
785def _ensure_cmap(cmap, accept_multivariate=False):
786 """
787 Ensure that we have a `.Colormap` object.
788
789 For internal use to preserve type stability of errors.
790
791 Parameters
792 ----------
793 cmap : None, str, Colormap
794
795 - if a `~matplotlib.colors.Colormap`,
796 `~matplotlib.colors.MultivarColormap` or
797 `~matplotlib.colors.BivarColormap`,
798 return it
799 - if a string, look it up in three corresponding databases
800 when not found: raise an error based on the expected shape
801 - if None, look up the default color map in mpl.colormaps
802 accept_multivariate : bool, default False
803 - if False, accept only Colormap, string in mpl.colormaps or None
804
805 Returns
806 -------
807 Colormap
808
809 """
810 if accept_multivariate:
811 types = (colors.Colormap, colors.BivarColormap, colors.MultivarColormap)
812 mappings = (mpl.colormaps, mpl.multivar_colormaps, mpl.bivar_colormaps)
813 else:
814 types = (colors.Colormap, )
815 mappings = (mpl.colormaps, )
816
817 if isinstance(cmap, types):
818 return cmap
819
820 cmap_name = mpl._val_or_rc(cmap, "image.cmap")
821
822 for mapping in mappings:
823 if cmap_name in mapping:
824 return mapping[cmap_name]
825
826 # this error message is a variant of _api.check_in_list but gives
827 # additional hints as to how to access multivariate colormaps
828
829 raise ValueError(_api.list_suggestion_error_msg('cmap', cmap, mpl.colormaps) +
830 "\nSee `matplotlib.bivar_colormaps()` and"
831 " `matplotlib.multivar_colormaps()` for"
832 " bivariate and multivariate colormaps")
833
834
835def _ensure_multivariate_data(data, n_components):

Callers 1

_set_cmapMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…