API reference
earthcarekit.colormap
Colormap utilities.
Notes
This module depends on other internal modules:
-
API reference
API reference
plot Notes
Cmap
Bases: ListedColormap
Colormap with categorical, gradient, and circular support.
This subclass of matplotlib.colors.ListedColormap adds utilities for
continuous and categorical color mappings. Supports labels, ticks,
normalization, blending, and transparency adjustments.
Attributes:
| Name | Type | Description |
|---|---|---|
categorical |
bool
|
Whether the colormap is discrete/categorical. |
gradient |
bool
|
Whether the colormap was generated from a gradient. |
circular |
bool
|
Whether the colormap wraps around cyclically. |
ticks |
list[float]
|
Optional tick positions for categorical plots. |
labels |
list[str]
|
Optional labels corresponding to ticks. |
norm |
Normalize | None
|
Normalization strategy for value mapping. |
values |
list
|
Associated values for categorical mapping. |
- API reference
- API reference
Source code in earthcarekit/colormap/_cmap.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
__init__
__init__(
colors: Sequence,
name: str = "colormap",
N: int | None = None,
categorical: bool = False,
ticks: List[float] | None = None,
labels: List[str] | None = None,
norm: Normalize | None = None,
values: List | None = None,
gradient: bool = False,
circular: bool = False,
)
Initialize a Cmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
Sequence
|
Sequence of colors (strings or ColorLike objects). |
required |
name
|
str
|
Name of the colormap. Defaults to "colormap". |
'colormap'
|
N
|
int | None
|
Number of discrete colors. Defaults to None. |
None
|
categorical
|
bool
|
Whether the colormap is discrete/categorical. Defaults to False. |
False
|
ticks
|
list[float] | None
|
Optional tick positions for categorical plots. Defaults to None. |
None
|
labels
|
list[str] | None
|
Optional labels corresponding to ticks. Defaults to None. |
None
|
norm
|
Normalize | None
|
Normalization strategy for value mapping. Defaults to None. |
None
|
gradient
|
bool
|
If True, generate intermediate gradient colors. Defaults to False. |
False
|
circular
|
bool
|
If True, colormap wraps around cyclically. Defaults to False. |
False
|
Source code in earthcarekit/colormap/_cmap.py
__new__
Allow instantiation from an existing Colormap or standard arguments.
blend
Return a copy of the colormap blended with a second color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Blend factor in the range [0, 1]. |
required |
blend_color
|
Color | str
|
Color to blend with. |
'white'
|
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
Blended colormap. |
Source code in earthcarekit/colormap/_cmap.py
from_colormap
classmethod
from_colormap(cmap: Colormap, N: int = 256, name: str | None = None) -> Cmap
Create a Cmap instance from an existing Matplotlib colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
Colormap
|
Source colormap to convert. |
required |
N
|
int
|
Number of discrete colors (if needed, e.g, for categorical colormaps with limited number of colors). Defaults to 256. |
256
|
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
New colormap. |
Source code in earthcarekit/colormap/_cmap.py
rgba_list
property
List of RGBA tuples representing all colors in the colormap.
set_alpha
set_alpha(value: float) -> Cmap
Return a copy of the colormap with modified alpha transparency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Alpha value in the range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
Colormap with updated transparency. |
Source code in earthcarekit/colormap/_cmap.py
to_categorical
to_categorical(
values_to_labels: Dict[Any, str] | int,
endpoint: bool | None = None,
use_discrete: bool | None = None,
) -> Cmap
Convert a colormap to categorical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values_to_labels
|
dict | int
|
Mapping from values to labels, or number of categories if int. |
required |
endpoint
|
bool | None
|
Whether the last color is included at 1.0. |
None
|
use_discrete
|
bool | None
|
If True, use the colormap's defined colors directly rather than sampling across its range. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
Categorical version of the colormap. |
- Tutorials Colormaps Categorical colormaps
Source code in earthcarekit/colormap/_cmap.py
to_discrete
to_discrete(n: int) -> Cmap
Convert a colormap to a discretized version of itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of steps (i.e., discrete colors). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
Discretized version of the colormap. |
Source code in earthcarekit/colormap/_cmap.py
cmaps
module-attribute
Dictionary of custom colormaps for earthcarekit.
combine_cmaps
combine_cmaps(
cmap1: str | Colormap | None,
cmap2: str | Colormap | None,
name: str = "combined_cmap",
n: int = 256,
) -> Cmap
Create a combined colormap from two colormaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap1
|
str | Colormap | None
|
Colormap to be modified. |
required |
cmap2
|
str | Colormap | None
|
Colormap to be modified |
required |
name
|
str
|
New colormap name. Defaults to "combined_cmap". |
'combined_cmap'
|
n
|
int
|
Number of colors. |
256
|
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
The combined colormap. |
- Tutorials Colormaps Combine colormaps
Source code in earthcarekit/colormap/_combine_cmaps.py
get_cmap
get_cmap(cmap: CmapLike | None, **kwargs) -> Cmap
Return a colormap given by cmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
CmapLike | None
|
|
required |
Returns: Cmap: The resolved colormap.
Source code in earthcarekit/colormap/_get_cmap.py
rename_cmap
shift_cmap
shift_cmap(
cmap: str | Colormap | None,
start: float = 0.0,
midpoint: float = 0.5,
stop: float = 1.0,
name: str = "shifted_cmap",
) -> Cmap
Create a colormap with its center point shifted to a specified value.
This function is useful for data with asymmetric ranges (e.g., negative min and positive max) where you want the center of the colormap to align with a specific value like zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str | Colormap | None
|
Colormap to be modified |
required |
start
|
float
|
Lower bound of the colormap range (value between 0 and |
0.0
|
midpoint
|
float
|
New center point of the colormap (value between 0 and 1). Defaults to 0.5. For data ranging from vmin to vmax where you want the center at value v, set midpoint = 1 - vmax/(vmax + abs(vmin)) |
0.5
|
stop
|
float
|
Upper bound of the colormap range (value between |
1.0
|
name
|
str
|
Name of the new colormap. Defaults to "shifted_cmap". |
'shifted_cmap'
|
Returns:
| Name | Type | Description |
|---|---|---|
Cmap |
Cmap
|
New colormap with shifted center |
- Tutorials Colormaps Shift the midpoint of a colormap