@@ -65,6 +65,10 @@ class ColormapDict(TypedDict):
65
65
class Colormap :
66
66
"""A colormap is a mapping from scalar values to RGB(A) colors.
67
67
68
+ The primary way to apply a colormap to data is to call the colormap object with
69
+ scalar values, which will return an array of RGBA colors. See
70
+ [`Colormap.__call__`][cmap.Colormap.__call__] for details.
71
+
68
72
Parameters
69
73
----------
70
74
value : Color | ColorStop | Iterable[Color | ColorStop] | dict[float, Color]
@@ -131,7 +135,65 @@ class Colormap:
131
135
"__weakref__" ,
132
136
)
133
137
134
- #: ColorStops dett
138
+ color_stops : ColorStops
139
+ """The color stops in the colormap.
140
+
141
+ This object is a sequence of color stops: a color
142
+ (RGBA) and a scalar position (0-1) in the gradient. This is the primary data
143
+ structure used to represent the colormap. See [`ColorStops`][cmap.ColorStops]
144
+ docstring for more information.
145
+ """
146
+
147
+ name : str
148
+ """A display name for the colormap.
149
+
150
+ If not provided explicitly, and if the colormap is a catalog colormap, this
151
+ will be set to `"namespace:name"`. If not a catalog colormap, it will be set
152
+ to the `identifier`, or fallback to `"custom colormap"`.
153
+ """
154
+
155
+ identifier : str
156
+ """An identifier for the colormaps.
157
+
158
+ If not provided, it will be generated from `name` by discarding any
159
+ characters that are not alphanumeric, spaces, dashes, or underscores, converting
160
+ to lowercase, replacing spaces and dashes with underscores, and prefacing with
161
+ `"_"` if the first character is a digit.
162
+ """
163
+
164
+ category : str | None
165
+ """An optional category for the colormap.
166
+
167
+ If not provided, and if the colormap is a catalog colormap, this will be set to
168
+ the category of the colormap.
169
+ """
170
+
171
+ interpolation : Interpolation
172
+ """The interpolation mode to use when mapping scalar values to colors.
173
+
174
+ Either `"linear"` or `"nearest"`, where `"linear"` is the default.
175
+ """
176
+
177
+ under_color : Color | None
178
+ """A color to use for values below 0 when converting scalars to colors.
179
+
180
+ If provided, and `Colormap.lut` is called with `with_over_under=True`, `under_color`
181
+ will be the third-to-last color in the LUT (`lut[-3]`).
182
+ """
183
+
184
+ over_color : Color | None
185
+ """A color to use for values above 1 when converting scalars to colors.
186
+
187
+ If provided, and `Colormap.lut` is called with `with_over_under=True`, `over_color`
188
+ will be the second-to-last color in the LUT (`lut[-2]`).
189
+ """
190
+
191
+ bad_color : Color | None
192
+ """A color to use for missing/bad values when converting scalars to colors.
193
+
194
+ If provided, and `Colormap.lut` is called with `with_over_under=True`, `bad_color`
195
+ will be the last color in the LUT (`lut[-1]`).
196
+ """
135
197
136
198
_catalog_instance : Catalog | None = None
137
199
@@ -197,12 +259,12 @@ def __init__(
197
259
if not name :
198
260
name = value if isinstance (value , str ) else "custom colormap"
199
261
200
- self .interpolation : Interpolation = _norm_interp (interpolation )
262
+ self .interpolation = _norm_interp (interpolation )
201
263
stops ._interpolation = self .interpolation
202
- self .color_stops : ColorStops = stops
203
- self .name : str = name
204
- self .identifier : str = _make_identifier (identifier or name )
205
- self .category : str | None = category
264
+ self .color_stops = stops
265
+ self .name = name
266
+ self .identifier = _make_identifier (identifier or name )
267
+ self .category = category
206
268
207
269
self .under_color = None if under is None else Color (under )
208
270
self .over_color = None if over is None else Color (over )
@@ -695,7 +757,10 @@ def to_pyqtgraph(self) -> pyqtgraph.ColorMap:
695
757
696
758
697
759
class ColorStop (NamedTuple ):
698
- """A color stop in a color gradient."""
760
+ """A color stop in a color gradient.
761
+
762
+ Just a named tuple with a `position` (`float`) and a `color` (`cmap.Color`).
763
+ """
699
764
700
765
position : float
701
766
color : Color
@@ -789,8 +854,15 @@ def _call_lut_func(self, X: np.ndarray) -> np.ndarray:
789
854
def parse (cls , colors : ColorStopsLike ) -> ColorStops :
790
855
"""Parse any colorstops-like object into a ColorStops object.
791
856
792
- This is the more flexible constructor.
793
- see `_parse_colorstops` docstring for details.
857
+ Each item in `colors` can be a color, or a 2-tuple of (position, color), where
858
+ position (the "stop" along a color gradient) is a float between 0 and 1. Where
859
+ not provided, color positions will be evenly distributed between neighboring
860
+ specified positions (if `fill_mode` is 'neighboring') or will be replaced with
861
+ `index / (len(colors)-1)` (if `fill_mode` is 'fractional').
862
+
863
+ Colors can be expressed as anything that can be converted to a Color, including
864
+ a string, or 3/4-sequence of RGB(A) values.
865
+
794
866
795
867
Parameters
796
868
----------
0 commit comments