Render options (grouped parameters)#
Glyph plot() / animate() calls take these typed objects in place of loose keyword arguments.
Each bundles a family of related options and exposes to_options(), which the glyph flattens into
its render settings — only the fields you set are applied, so a group never clobbers a glyph's own
defaults. (The ArrayGlyph-specific input objects — RgbBands, PointOverlay, FrameLabel,
PanelLabels — are documented on the ArrayGlyph page.)
ColorScaling#
The colour-scale (norm) selector: plot(color=ColorScaling.power(gamma=0.5)),
ColorScaling.sym_log(...), ColorScaling.boundary(bounds=[...]), ColorScaling.midpoint(at=0),
ColorScaling.linear().
cleopatra.styling.scaling.ColorScaling
dataclass
#
The colour-scale group: a scale kind plus its scale-specific knobs.
Prefer the variant constructors (linear, power, sym_log,
boundary, midpoint) over the raw dataclass -- each exposes only
the fields its scale uses, so nonsensical combinations (e.g. a
midpoint on a linear scale) cannot be built.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
ColorScale
|
The scale kind ( |
gamma |
float
|
Exponent for the |
line_threshold |
float
|
Linear-region threshold for |
line_scale |
float
|
Linear-region scale factor for |
bounds |
list[float] | None
|
Explicit bin edges for |
center |
float
|
Centre value for the |
Source code in src/cleopatra/styling/scaling.py
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
boundary(bounds=None)
classmethod
#
A discrete (BoundaryNorm) colour scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list[float] | None
|
Explicit bin edges. When |
None
|
Examples:
- Explicit edges are carried through:
Source code in src/cleopatra/styling/scaling.py
build_norm(ticks, levels=None, extend=None)
#
Build the matplotlib norm and colorbar keyword arguments.
The colour-scale logic that used to live in
Glyph._create_norm_and_cbar_kw. vmin/vmax are read from the
first and last tick; levels and extend are cross-group inputs
(contour discretisation and colorbar arrow extension) passed in by
the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ticks
|
ndarray
|
Tick positions for the colorbar; |
required |
levels
|
int | list[float] | ndarray | None
|
Optional discretisation for the |
None
|
extend
|
str | None
|
Colorbar arrow extension. When |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Normalize | None, dict[str, Any]]
|
tuple[Normalize or None, dict]: The norm ( |
Examples:
- A linear scale with no levels yields no norm and passes the ticks straight through:
levelson the linear scale builds aBoundaryNormand defaultsextendto"both":
Source code in src/cleopatra/styling/scaling.py
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
from_options(options)
classmethod
#
Build a ColorScaling from a flat default_options dict.
The bridge between the legacy flat-key storage every glyph still
uses internally and this object's behaviour. Reads the six
colour-scale keys, validating color_scale with the same
actionable error the flat path raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
dict[str, Any]
|
A glyph's |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ColorScaling |
ColorScaling
|
The reconstructed scale object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Round-trips the flat keys back into an object:
Source code in src/cleopatra/styling/scaling.py
linear()
classmethod
#
A plain linear colour scale (matplotlib's default norm).
Examples:
- The linear scale carries no extra knobs:
Source code in src/cleopatra/styling/scaling.py
midpoint(at=0)
classmethod
#
A midpoint-anchored diverging colour scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
float
|
The value pinned to the colormap centre. Defaults to |
0
|
Examples:
- Anchor the colormap centre at a chosen value:
Source code in src/cleopatra/styling/scaling.py
power(gamma=0.5)
classmethod
#
A power-law (PowerNorm) colour scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
float
|
The power exponent. Defaults to |
0.5
|
Examples:
- Only
gammais exposed:
Source code in src/cleopatra/styling/scaling.py
sym_log(threshold=0.0001, scale=0.001)
classmethod
#
A symmetric-log (SymLogNorm) colour scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The linear-region half-width ( |
0.0001
|
scale
|
float
|
The linear-region scale factor ( |
0.001
|
Examples:
- Exposes the two
sym-lognormknobs:
Source code in src/cleopatra/styling/scaling.py
to_options()
#
Flatten back to the default_options keys the engine reads.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
The six colour-scale keys, with |
Examples:
- Emits the flat keys a glyph merges into
default_options:
Source code in src/cleopatra/styling/scaling.py
Contour#
Discrete colour levels and inline contour labels: plot(contour=Contour(levels=6, labels=True)).
cleopatra.styling.params.Contour
dataclass
#
Contour discretisation and inline-label options.
Groups the levels / labels / label_kw options. levels applies
to every colour-mapped glyph that discretises a scale (array, vector,
flow, polygon, scatter, kde); labels / label_kw draw inline numeric
labels on isolines and are honoured only by the glyphs that render
contour lines (ArrayGlyph with kind="contour", MeshGlyph node
contours).
Attributes:
| Name | Type | Description |
|---|---|---|
levels |
int | Sequence[float] | None
|
Discrete colour levels -- an int count or an explicit
sequence of edges. |
labels |
bool | None
|
Draw inline numeric labels on isolines. |
label_kw |
dict[str, Any] | None
|
Extra keyword arguments forwarded to |
Examples:
- Only the set fields are emitted:
Source code in src/cleopatra/styling/params.py
to_options()
#
Flatten the explicitly-set fields into default_options keys.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
|
Source code in src/cleopatra/styling/params.py
CellValues#
Per-cell value-text overlay (ArrayGlyph): plot(cells=CellValues(show=True, size=10)).
cleopatra.styling.params.CellValues
dataclass
#
Per-cell value-text display options (ArrayGlyph only).
Groups the display_cell_value / num_size /
background_color_threshold options that overlay each cell's numeric
value on an imshow / pcolormesh render.
Attributes:
| Name | Type | Description |
|---|---|---|
show |
bool | None
|
Draw each cell's value as text. |
size |
int | None
|
Font size of the cell-value text. |
background_threshold |
float | None
|
Value above which the text switches to the
light colour (for contrast against a dark cell). |
Examples:
- Enable the overlay with a custom font size:
Source code in src/cleopatra/styling/params.py
to_options()
#
Flatten the explicitly-set fields into default_options keys.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
|
Source code in src/cleopatra/styling/params.py
DataStyle#
Named preset, relief shading, and per-call preset overrides:
plot(data_style=DataStyle(style="topography", hillshade=True)).
cleopatra.styling.params.DataStyle
dataclass
#
Named data-style preset, relief-shading, and per-call preset overrides.
Groups the style / hillshade options honoured by ArrayGlyph,
MeshGlyph, and KDEGlyph, plus the bands / alpha / alpha_range
per-call overrides of an active ArrayGlyph preset. Each field has three
states: left unset (keep the glyph's current value -- these options are
sticky), set to a value (apply it), or set explicitly to None (clear the
preset / disable hillshade / drop the override). to_options() emits a key
only for a field that was given (set or explicit None), never for an
unset one.
The bands / alpha / alpha_range fields override just one aspect of a
styled render while keeping the rest of the preset; they are only
meaningful alongside a style (they replace one field of the active
DATA_STYLES preset). bands rebands the scale (replacing the preset's
levels); alpha sets a constant opacity and alpha_range a value-linked
one -- the two are mutually exclusive and resolved downstream (a constant
alpha wins). They apply to a continuous/levelled preset only; a
categorical (class-colour) preset renders opaque with its fixed class
colours and ignores these overrides.
Attributes:
| Name | Type | Description |
|---|---|---|
style |
str | None | _Unset
|
Name of a |
hillshade |
bool | dict[str, Any] | None | _Unset
|
Relief-shade a regular-grid DEM -- |
bands |
int | None | _Unset
|
Discrete band count partitioning the preset's value range,
replacing the preset's own |
alpha |
float | None | _Unset
|
Constant layer opacity in |
alpha_range |
tuple[float, float] | None | _Unset
|
|
Examples:
- Select a preset and turn on relief shading:
- Override a styled preset's banding and opacity per call:
- An unset field is omitted (keeping the sticky value); an
explicit
Noneis emitted (clearing it):
Source code in src/cleopatra/styling/params.py
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 | |
__post_init__()
#
Validate alpha_range is a (vmin, vmax) numeric pair when given.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/cleopatra/styling/params.py
for_apply_style(style, hillshade=_UNSET)
classmethod
#
Build the DataStyle an apply_style(...) call forwards to plot.
Folds a preset style and an optionally-forwarded hillshade into one
object: when hillshade is left unset (the default sentinel) it is
omitted so any sticky relief shading is kept; an explicit value (a dict,
True/False, or None to clear) flows through to
DataStyle(hillshade=...). Centralises the sentinel-gated construction
that the apply_style helpers of ArrayGlyph, MeshGlyph, and
KDEGlyph previously each hand-rolled with their own sentinels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str | None
|
The |
required |
hillshade
|
bool | dict[str, Any] | None | _Unset
|
Relief-shading override, or the |
_UNSET
|
Returns:
| Name | Type | Description |
|---|---|---|
DataStyle |
DataStyle
|
|
Examples:
>>> from cleopatra.styling.params import DataStyle
>>> DataStyle.for_apply_style("dem").to_options()
{'style': 'dem'}
>>> DataStyle.for_apply_style("dem", hillshade=True).to_options()
{'style': 'dem', 'hillshade': True}
Source code in src/cleopatra/styling/params.py
to_options()
#
Flatten the explicitly-given fields into default_options keys.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
|
Source code in src/cleopatra/styling/params.py
Classify#
Categorical / classed colour schemes on the scatter / vector / flow / polygon glyphs:
plot(classify=Classify(scheme="categorical", k=5)).
cleopatra.styling.params.Classify
dataclass
#
Value-classification (choropleth) options.
Groups the scheme / k / category_legend_kwargs options honoured
by the glyphs whose colour mapping routes through
Glyph._prepare_scalar_mapping -- VectorGlyph, FlowGlyph,
PolygonGlyph, ScatterGlyph.
Attributes:
| Name | Type | Description |
|---|---|---|
scheme |
str | Sequence[float] | None
|
A |
k |
int | None
|
The class count for count/width schemes. |
category_legend_kwargs |
dict[str, Any] | None
|
Extra keyword arguments forwarded to the
legend a |
Examples:
- A quantile scheme with four classes:
Source code in src/cleopatra/styling/params.py
to_options()
#
Flatten the explicitly-set fields into default_options keys.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
|
Source code in src/cleopatra/styling/params.py
ColorBar#
Colorbar placement, caption, and sizing: plot(colorbar=ColorBar(location="bottom", label="mm/day")).
Pass colorbar=True/False for the simple cases.
cleopatra.styling.colorbar.ColorBar
#
Placement (and backing box) for the colorbar plot / animate draws.
Bundles the colorbar-layout choices -- which edge it sits on, whether it
is inset inside the frame, and its backing box -- into one value passed
as plot(colorbar=...) / animate(colorbar=...), mirroring FrameLabel.
Pass colorbar=True / False / None for the simple cases and a
ColorBar for placement control.
Attributes:
| Name | Type | Description |
|---|---|---|
location |
Edge the colorbar sits on -- |
|
orientation |
Bar orientation -- |
|
inside |
When |
|
box |
Backing panel behind the scale, so the data does not show through
its labels. |
|
label_color |
Colour of the scale's title text -- the colorbar's axis
label and, for a |
|
tick_color |
Colour of the tick labels (the numbers) of a real colorbar
and, for a |
|
label |
Caption text for the scale (the colorbar's title). |
|
length |
Bar length as a fraction of the axis (e.g. |
|
label_size |
Font size of the caption. |
|
label_rotation |
Rotation of the caption in degrees. |
|
label_location |
Where the caption sits along the bar (e.g. |
|
ticks_spacing |
Spacing between the colorbar's ticks. |
Examples:
- An inside colorbar on the right -- its box defaults on:
- Black title + tick numbers, outside on the bottom (no box):
- A captioned bar, fully specified through the spec (no loose kwargs):
Source code in src/cleopatra/styling/colorbar.py
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 385 386 387 388 389 390 391 392 | |
__init__(*, location=None, orientation=None, inside=False, box=None, label_color=None, tick_color=None, label=None, length=None, label_size=None, label_rotation=None, label_location=None, ticks_spacing=None)
#
Initialise a ColorBar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Literal['left', 'right', 'top', 'bottom'] | None
|
Edge to sit on ( |
None
|
orientation
|
Literal['vertical', 'horizontal'] | None
|
Bar orientation ( |
None
|
inside
|
bool
|
Inset the colorbar inside the frame, by default |
False
|
box
|
bool | str | dict | None
|
Backing panel for an inside colorbar ( |
None
|
label_color
|
str | None
|
Colour of the scale title / colorbar label (and the
swatch title for a |
None
|
tick_color
|
str | None
|
Colour of the colorbar's tick numbers; |
None
|
label
|
str | None
|
Caption text (scale title); |
None
|
length
|
float | None
|
Bar length as a fraction of the axis; |
None
|
label_size
|
float | None
|
Caption font size; |
None
|
label_rotation
|
float | None
|
Caption rotation in degrees; |
None
|
label_location
|
str | None
|
Caption placement along the bar (distinct from
|
None
|
ticks_spacing
|
float | None
|
Spacing between the colorbar's ticks; |
None
|
Source code in src/cleopatra/styling/colorbar.py
reset_options()
classmethod
#
default_options updates for a default, sticky-clearing colorbar.
The dict colorbar=True applies: it draws a default bar and resets the
resettable cbar_* family to STYLE_DEFAULTS, so a reused glyph does
not inherit a prior sticky spec's placement or caption. Distinct from
to_options, which maps a specific spec's fields and omits unset
ones; this resets the whole cbar_* family to the defaults.
ticks_spacing is deliberately excluded: it is glyph-specific
(KDEGlyph, for one, auto-derives it from the data range when unset),
so a single shared reset value could not restore each glyph's own
default -- it is therefore left untouched by colorbar=True.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
Examples:
- The reset always enables the bar and clears the placement:
Source code in src/cleopatra/styling/colorbar.py
resolve(colorbar)
classmethod
#
Translate a colorbar= argument into default_options updates.
Owns the full None / False / True / ColorBar dispatch: None
leaves the colorbar options untouched; False suppresses the bar;
True resets to a default bar via reset_options; a ColorBar
instance maps its fields via to_options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colorbar
|
bool | ColorBar | None
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Updates to merge into |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
>>> from cleopatra.styling.colorbar import ColorBar
>>> ColorBar.resolve(False)
{'add_colorbar': False}
>>> ColorBar.resolve(ColorBar(location="left", inside=True))["cbar_location"]
'left'
>>> "cbar_label" in ColorBar.resolve(ColorBar(location="right"))
False
Source code in src/cleopatra/styling/colorbar.py
specifies_placement()
#
Whether this spec explicitly requests a placement or orientation.
True when any of location, inside, or orientation is set -- the
spec asks for a specific colorbar rather than leaving the default. Used
to decide whether a styled (preset) render should still draw a colorbar.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Examples:
- A placement edge counts as specified; a bare spec does not:
Source code in src/cleopatra/styling/colorbar.py
to_options()
#
Map this spec's fields onto the cbar_* default_options keys.
Mirrors the other grouped styling objects' to_options: the object
owns the translation from its own fields to the flat render options
create_color_bar reads. Placement fields are always emitted (so a
reused glyph's prior placement is overwritten); the caption / sizing /
orientation / tick-spacing fields are emitted only when set, leaving an
unset field at the existing default.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
Examples:
- Placement maps onto
cbar_*; unset caption fields are omitted: