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

Class ColormapRegistry

lib/matplotlib/cm.py:66–230  ·  view source on GitHub ↗

r""" Container for colormaps that are known to Matplotlib by name. The universal registry instance is `matplotlib.colormaps`. There should be no need for users to instantiate `.ColormapRegistry` themselves. Read access uses a dict-like interface mapping names to `.Colormap`\s::

Source from the content-addressed store, hash-verified

64
65
66class ColormapRegistry(Mapping):
67 r"""
68 Container for colormaps that are known to Matplotlib by name.
69
70 The universal registry instance is `matplotlib.colormaps`. There should be
71 no need for users to instantiate `.ColormapRegistry` themselves.
72
73 Read access uses a dict-like interface mapping names to `.Colormap`\s::
74
75 import matplotlib as mpl
76 cmap = mpl.colormaps['viridis']
77
78 Returned `.Colormap`\s are copies, so that their modification does not
79 change the global definition of the colormap.
80
81 Additional colormaps can be added via `.ColormapRegistry.register`::
82
83 mpl.colormaps.register(my_colormap)
84
85 To get a list of all registered colormaps, you can do::
86
87 from matplotlib import colormaps
88 list(colormaps)
89 """
90 def __init__(self, cmaps):
91 self._cmaps = cmaps
92 self._builtin_cmaps = tuple(cmaps)
93
94 def __getitem__(self, item):
95 cmap = _api.getitem_checked(self._cmaps, colormap=item, _error_cls=KeyError)
96 return cmap.copy()
97
98 def __iter__(self):
99 return iter(self._cmaps)
100
101 def __len__(self):
102 return len(self._cmaps)
103
104 def __str__(self):
105 return ('ColormapRegistry; available colormaps:\n' +
106 ', '.join(f"'{name}'" for name in self))
107
108 def __call__(self):
109 """
110 Return a list of the registered colormap names.
111
112 This exists only for backward-compatibility in `.pyplot` which had a
113 ``plt.colormaps()`` method. The recommended way to get this list is
114 now ``list(colormaps)``.
115 """
116 return list(self)
117
118 def register(self, cmap, *, name=None, force=False):
119 """
120 Register a new colormap.
121
122 The colormap name can then be used as a string argument to any ``cmap``
123 parameter in Matplotlib. It is also available in ``pyplot.get_cmap``.

Callers 1

cm.pyFile · 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…