Maps (matplotlib)#
Map is the default backend's host: a matplotlib figure with a display CRS, one axes, and a list of layers it
can re-order, hide and replace after they are drawn.
from digitalearth import Map
m = Map(crs=3857)
m.field(dataset, cmap="terrain")
m.points(stations, name="obs")
m.lines(rivers, column="discharge", width=1.5)
m.coastlines()
m.colorbar()
m.save("map.png")
colorbar() with no argument keys the most recent layer that is coloured by a value — a coastline, a
basemap or a text label added after the data cannot take the key. Name a layer (colorbar("obs")) to key that
one instead, and colorbars() keys every layer that has a key to show. The request is recorded on the layer,
so the bar moves, hides and disappears with it.
Every input is reprojected to the display CRS through pyramids and drawn on a plain axes — there is no
Cartopy, because the projection is applied to the data rather than to the axes. The rendering itself is
cleopatra's: each builder assembles a glyph and hands the styling keywords straight to it, which is why
cmap, levels, figsize and the cbar_* family are documented there rather than here.
What this tier is for#
Scientific field rendering and anything that has to come back as a file: rasters, contours, unstructured
meshes, vector and flow fields, KDE, ensemble series and animations. It is the one tier installed without an
extra, which is all that distinguishes it: digitalearth.interactive, digitalearth.web and
digitalearth.three_d are peers, answering to the same method names wherever they can draw the same thing,
and each owns what the others have no primitive for.
The layer list#
A builder returns the artist it drew and records a layer beside it, addressed by the name= you gave it (or a
generated id). layer_ids lists them in draw order, and move_layer, remove_layer, replace_layer and
set_visible work on that list afterwards, so a figure can be rearranged without being rebuilt. Layers sit in
bands — underlay, reference, data, overlay — and a later call cannot slip under an earlier band, so a
basemap stays under the data and a label stays over it however the calls were ordered.
figure_spec is the whole figure as a value: its panels, their layers, the view each is drawn in and the
furniture anchored to them. That description is what the other tiers read back, and it is the reason a layer
records its recipe (via) rather than the method that drew it.
What field accepts#
A pyramids Dataset, a path or URL to a raster — and a bare 2-D NumPy array, for the "just show me this
grid" case. Such a layer is not georeferenced: it is placed at its own indices, nothing is reprojected, and no
georeferenced layer may share the figure with it (a basemap, a coastline and a reprojected raster are all in
the display CRS, so mixing them is refused rather than drawn with one of them as an invisible speck). Nodata in
a bare array is a masked array, since there is no sidecar to carry a no_data_value. Anything else is refused
by name, saying what the call takes.
The domain the ramp spans#
robust=True clips the colour limits to the 2nd and 98th percentile of the band, xarray-style, so a single
outlier stops flattening the rest of the field.
center= states the value a diverging scale is built around — zero for an anomaly, a difference or a
trend, and whatever the reference is otherwise. The limits are symmetrised on it, so one unit of departure is
one step of colour on either side, and the ramp becomes a diverging one centred there: its lightest colour
lands on the centre and the two arms darken away from it. color_scale="midpoint", midpoint= is the other
spelling, and a different request — it keeps the data's own asymmetric limits and moves the colour centre
instead. Both get the diverging ramp.
m.field(anomaly, center=0, robust=True)
m.field(anomaly, color_scale="midpoint", midpoint=0) # asymmetric limits, colour centred on zero
The ramp is only substituted where no colormap was named: cmap= is always what draws. And the centre has to
be inside the data — a ramp centred outside it draws every value in one arm, which is worse than the
sequential ramp it would replace — so for a centre the band does not straddle the diverging ramp is
declined, the resolved colormap is kept, and the decline is logged at WARNING naming the centre and the
range it measured.
Only the ramp is declined. center= is cleopatra's own keyword and it symmetrises the colour limits whether
the band straddles the centre or not, so an off-band centre still widens the colour domain to reach it:
measured, a band running 12 to 88 drawn with center=0 goes through limits (-88.0, 88.0) instead of
(12.0, 88.0), leaving the data in the top 43% of the ramp. The color_scale="midpoint", midpoint=
spelling has no such effect — it keeps the data's own limits — so an off-band centre there costs nothing but
the ramp. Either way the remedy the warning names is the same: move the centre inside the data, or drop it.
The colours a ramp cannot place#
Three values fall outside a colour ramp, and a field render takes a colour for each: missing= for a cell with
no value, under= for a value below vmin and over= for one above vmax. They are stated on the call and
folded onto the layer's colormap, so they also reach the figure's description — the layer's colour Scale
carries them, so a backend that read them back could colour the same values the same way. None does yet: the
static style schema declares missing/over/under and the interactive one declares none of the three, so the
round trip that works today is this tier reading back its own figure.
Stating one is opt-in and leaves the rest alone. Without missing= a nodata cell keeps matplotlib's default
— fully transparent, so the gap shows through — and without over= a clipped value keeps the ramp's own end
colour, which is why a field clipped at vmax reads the same as one that really peaks there. A colormap you
built yourself keeps the extremes it already carried; only the ones named in the call are restated.
Small multiples on one scale#
facet(stack) draws a raster stack — a multi-band Dataset, a DatasetCollection or a list of frames — as
one panel per frame, and resolves the colour scale once over the whole stack: the frames are warped into
the display CRS and measured together, so every panel colours one value the same way, and a named scheme is
cut into one set of class edges for all of them. col_wrap folds the row, col/labels title the panels, and
one colorbar spans them. Each panel is an ordinary Map, returned for further drawing.
from digitalearth.static import facet
fig, maps = facet(monthly_rain, crs=4326, col="month", labels=months, col_wrap=4, cbar_label="mm")
for m in maps:
m.coastlines()
fig.savefig("rain.png")
digitalearth.static.panels.figure.facet(stack, *, col=None, col_wrap=None, labels=None, kind='field', band=DEFAULT_BAND, crs=3857, globe=False, figsize=None, colorbar=True, cbar_label=None, **style)
#
Draw a raster stack as small multiples — one panel per frame — on one shared colour scale.
Small multiples are read against each other, so the scale is resolved once over the whole stack
rather than per panel: the frames are warped into the display CRS and measured together, vmin/vmax
become the stack's range, and a named scheme is cut into one set of class edges over every frame —
scheme="categorical" included, whose class codes are pooled over the stack so one code is one colour
on every panel. Each panel is an ordinary :class:Map from :func:grid, so its frame is a described
layer and the panel takes a basemap, coastlines or a graticule like any other map. One colorbar spans the
panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
Any
|
A multi-band |
required |
col
|
str | None
|
What the panels are, as each title names it — |
None
|
col_wrap
|
int | None
|
Panels per row; the rest wrap onto further rows, and the unused slots of the last row are
hidden. |
None
|
labels
|
Sequence[Any] | None
|
One label per panel for its title, in place of the index ( |
None
|
kind
|
str
|
The render — |
'field'
|
band
|
int
|
The band each frame of a collection or sequence is drawn from. Ignored for a multi-band dataset, whose bands are the panels. |
DEFAULT_BAND
|
crs
|
Any
|
Display CRS of every panel. |
3857
|
globe
|
bool
|
Draw every panel on a globe frame. |
False
|
figsize
|
tuple[float, float] | None
|
Figure size in inches; |
None
|
colorbar
|
bool
|
Draw one colorbar spanning the panels (default |
True
|
cbar_label
|
str | None
|
The colorbar's label. |
None
|
**style
|
Any
|
Styling for every panel, forwarded to the render ( |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, list[Map]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- Four frames on one row, one scale, titled by month:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import facet >>> geo = GeoReference(geo=(0.0, 1.0, 0.0, 4.0, 0.0, -1.0), epsg=4326) >>> frames = [ ... Dataset.from_array(arr=np.full((4, 4), 10.0 * i), geo_ref=geo, no_data_value=-9999.0) ... for i in range(4) ... ] >>> fig, maps = facet(frames, crs=4326, col="month", labels=["Jan", "Feb", "Mar", "Apr"]) >>> [m.ax.get_title() for m in maps] ['month = Jan', 'month = Feb', 'month = Mar', 'month = Apr'] >>> {m.layers[-1][1].get_clim() for m in maps} {(0.0, 30.0)} >>> plt.close(fig) # one figure holds every panel, so one close is the whole facet - Wrap onto rows of three; the last row's spare slots are hidden:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import facet >>> geo = GeoReference(geo=(0.0, 1.0, 0.0, 4.0, 0.0, -1.0), epsg=4326) >>> frames = [ ... Dataset.from_array(arr=np.full((4, 4), float(i)), geo_ref=geo, no_data_value=-9999.0) ... for i in range(4) ... ] >>> fig, maps = facet(frames, crs=4326, col_wrap=3, colorbar=False) >>> maps[0].ax.get_subplotspec().get_geometry()[:2], sum(not ax.get_visible() for ax in fig.axes) ((2, 3), 2) >>> plt.close(fig) - A categorical stack cuts its classes over every frame, so the second frame's codes carry on the
palette rather than restarting it — code 1 is its first colour and code 3 its third:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from matplotlib.colors import to_hex >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import facet >>> geo = GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326) >>> early = Dataset.from_array( ... arr=np.array([[1.0, 1.0], [2.0, 2.0]]), geo_ref=geo, no_data_value=-9999.0 ... ) >>> late = Dataset.from_array( ... arr=np.array([[3.0, 3.0], [4.0, 4.0]]), geo_ref=geo, no_data_value=-9999.0 ... ) >>> fig, maps = facet([early, late], crs=4326, scheme="categorical", colorbar=False) >>> art = [m.layers[-1][1] for m in maps] >>> [to_hex(art[0].cmap(art[0].norm(code))) for code in (1.0, 2.0)] ['#1f77b4', '#ff7f0e'] >>> [to_hex(art[1].cmap(art[1].norm(code))) for code in (3.0, 4.0)] ['#2ca02c', '#d62728'] >>> [m.layers[-1][1].get_clim() for m in maps] [(0.5, 4.5), (0.5, 4.5)] >>> plt.close(fig) - A stack where every cell is nodata still draws its panels, but no colorbar: the figure holds the
two panels and nothing else, where a measurable stack of the same shape holds a third axes for the
bar.
kwithout aschemeis refused outright, since it would classify nothing:>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import facet >>> geo = GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326) >>> blank = [ ... Dataset.from_array( ... arr=np.full((2, 2), -9999.0), geo_ref=geo, no_data_value=-9999.0 ... ) ... for _ in range(2) ... ] >>> fig, maps = facet(blank, crs=4326) >>> len(maps), len(fig.axes) (2, 2) >>> maps[0].layers[-1][1].get_clim() (0.0, 1.0) >>> try: ... facet(blank, crs=4326, k=4) ... except ValueError as error: ... print(str(error)[:69]) facet(k=4) counts the classes a scheme cuts, so it classifies nothing >>> plt.close(fig)
See Also
grid: the panels alone, for a layout that draws something different on each. shared_colorbar: the spanning bar on its own.
Source code in src/digitalearth/static/panels/figure.py
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 | |
Hatching a mask#
contours(..., filled=True, hatches=[...]) gives each band between levels a hatch pattern, and fill=False
leaves the bands uncoloured so only the hatching draws — the usual way to mark a significance or uncertainty
mask over another field without spending its colours. legend() on such a layer keys the bands it marks by
their pattern; hatch_color= colours the strokes on the map and in the key alike.
labels= names the bands levels= declares — one label per band, the same count as hatches= — and the
labels of the bands the map does not mark are dropped alongside their rows. The count therefore comes from the
call and not from the raster, so a labels= written against one reading of the field keeps working when the
data stops reaching a band (or starts reaching another).
m.field(trend, cmap="RdBu_r")
m.contours(p_value, levels=[0, 0.05, 1], filled=True, hatches=["///", ""], fill=False, name="sig")
m.legend("sig", labels=["p < 0.05", "not significant"]) # two declared bands; only the hatched one is keyed
A layer that marks none of its bands — every pattern empty, or every hatched band past where the data reaches
— has no rows to key, so legend() draws nothing rather than an empty framed box, and logs
legend(): layer 'sig' marks none of its 4 hatched bands, … at WARNING. The guide is still recorded on the
layer, so the figure says what was asked for.
Overlays computed from the globe itself#
nightshade(when) shades the night side of the day/night terminator at one instant, and tissot() draws
Tissot's indicatrices — circles of one ground radius, shown as the projection distorts them. cleopatra computes
both in lon/lat (cleopatra.basemap.solar) and they are projected into the display CRS through pyramids, so a
Web Mercator map shows the polar night reaching the pole and the indicatrices swelling toward it. On a globe
the night side is filled only where it faces the viewer, and a circle on the far side is left out.
from datetime import datetime, timezone
m = Map(crs=3857)
m.nightshade(datetime(2026, 6, 21, 12, tzinfo=timezone.utc), alpha=0.3)
m.nightshade("2026-06-21T12:00:00", refraction=-6.0, alpha=0.15) # civil twilight
m.tissot(edgecolor="crimson") # a world grid of 500 km circles
digitalearth.static.map.Map
#
Bases: RasterMixin, VectorMixin, DecorationMixin, InsetMixin, ProjectionMixin, AnimationMixin, GeoLayerBase
A geospatial :class:~digitalearth.static.core.scene.Scene that reprojects to a display CRS.
The tier's workhorse, and a composition rather than a class with methods of its own: every
capability lives in one of the six mixins under digitalearth.static.builders — RasterMixin (fields,
composites, spaghetti), VectorMixin (points, polygons, unstructured, flow, u/v fields),
DecorationMixin (text, annotate, basemap, Natural-Earth layers), InsetMixin (inset,
mark_extent), ProjectionMixin (extent, domain, globe frame, save/show) and AnimationMixin
(animate, rotate) — and map.py only lists them. tests/static/test_map_composition.py pins that
MRO, so a seventh mixin fails it until the list is updated.
Every data builder returns Self, so calls chain (m.field(ds).coastlines().colorbar()), and the
matplotlib artist a layer drew is reached by name through :meth:~digitalearth.static.core.scene.Scene.artist
— never through the renderer's private record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
Any
|
Display CRS as an EPSG int / string / CRS (anything |
3857
|
domain
|
Any
|
A registered region name ( |
None
|
ax
|
Any
|
Existing axes to draw on (a new figure/axes is created when |
None
|
fig
|
Any
|
Figure owning |
None
|
figsize
|
tuple[float, float]
|
New-figure size in inches when one is created; |
(8, 8)
|
globe
|
bool
|
Draw the projection boundary/graticule and clip layers to it (an orthographic globe). |
False
|
strict
|
bool
|
When |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
crs |
The display CRS every layer is reprojected to, exactly as it was passed. |
|
domain |
The configured domain (or |
|
strict |
bool
|
Whether a layer that would draw nothing raises instead of being skipped. |
Examples:
- Create a map in Web Mercator and read its display CRS; it describes nothing yet:
- Render a reprojected raster and chain decoration onto it — each builder hands the map back, so
the layer ids accumulate in draw order:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from pyramids.dataset import Dataset >>> from digitalearth.static import Map >>> ds = Dataset.read_file("examples/data/acc4000.tif") >>> m = Map(crs=ds.epsg) # same CRS -> no reprojection >>> m.field(ds).coastlines(name="coast") is m True >>> m.layer_ids ['raster-1', 'coast'] >>> m.close() - A domain is remembered rather than applied: the axes is framed only once
set_domain()asks for it, and the attribute survives the framing:
Source code in src/digitalearth/static/map.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 | |
layer_ids
property
#
The ids of the layers this scene draws, in draw order, bottom first.
Returns:
| Type | Description |
|---|---|
list[str]
|
One id per described layer. A layer the caller named carries that name, with surrounding |
list[str]
|
whitespace removed; an unnamed one gets a generated id counting the layers of its kind — |
list[str]
|
|
list[str]
|
order. It counted the figure until review R2-M10, while this sentence already said otherwise |
list[str]
|
(review R2-L2). |
figure_spec
property
#
What the scene draws, as data: its layers, their sources and the view.
Returns:
| Name | Type | Description |
|---|---|---|
A |
FigureSpec
|
class: |
FigureSpec
|
the tree in draw order and whose sources are what each builder was given. |
|
FigureSpec
|
It carries the plain half of the caller's styling and no more: a keyword passed through |
|
FigureSpec
|
|
|
FigureSpec
|
it, and held beside the layer |
|
FigureSpec
|
(:attr: |
|
FigureSpec
|
described |
|
FigureSpec
|
dash tuple, a per-pixel array or a |
|
FigureSpec
|
A scene built from data already in memory can be handed straight to a renderer, but not written: |
|
FigureSpec
|
|
|
FigureSpec
|
be unreadable everywhere else. Give a builder a path or a URL to get a figure that can be stored. |
viewport
property
#
Where the map is looking, as a value — including the region it has been framed on.
Returns:
| Name | Type | Description |
|---|---|---|
Viewport
|
The view :class: |
|
Viewport
|
declared domain and the globe flag, carrying the region the last framing call asked for when |
|
Viewport
|
there has been one. A view holds a region or a named domain, never both, so a map that was |
|
Viewport
|
built with a |
|
what |
Viewport
|
meth: |
Viewport
|
domain from sitting beside a live frame. |
|
Viewport
|
Before order 26 this always answered |
|
Viewport
|
described itself as unframed, which is why the basemap coverage guard had to record the axes |
|
Viewport
|
extent on its own layer instead of reading it off the panel. |
|
Viewport
|
A frame recorded in a CRS the map no longer draws in is not reported, and is not converted |
|
Viewport
|
either. A rotation swaps the display CRS between frames, and the region a previous frame was |
|
Viewport
|
globally framed on is often one the next projection cannot show at all — so the honest answer |
|
Viewport
|
there is that nothing has framed this view yet, rather than a rectangle reprojected across a |
|
Viewport
|
limb or a refusal raised from a property. |
field(data, *, band=DEFAULT_BAND, cmap=None, limits=None, opacity=None, name=None, visible=True, **kwargs)
#
Render a raster band as a coloured field — a pixel grid (ArrayGlyph kind="imshow").
A bare 2-D numpy array is drawn too — the "just show me this grid" case, which was
StaticGlyph.plot(arr) until that class was deleted and which nothing took over (#343). Such a
layer is not georeferenced, and that is not a detail:
- its coordinates are its own indices — the column index on x, the row index on y, cell centres
on the integers and the image covering
[-0.5, cols - 0.5] x [-0.5, rows - 0.5], with the first row drawn at the top as matplotlib draws every array; - nothing is reprojected. An array declares no CRS, so :attr:
crssays nothing about where it is and no warp is attempted — :meth:~digitalearth.static.builders.base.GeoLayerBase._reprojecthands it straight back and the layer'sSourcecarriescrs=None; - no georeferenced layer may share the figure. A basemap, a coastline, a graticule and a
reprojected raster are all placed in the display CRS, so mixing one in is refused by
:meth:
~digitalearth.static.core.scene.Scene._require_one_placementrather than drawn with the array as an invisible speck beside it; - a globe frame is refused for the same reason, at this call;
- :meth:
~digitalearth.static.builders.projection.ProjectionMixin.set_boundsstill frames the figure, and itsboundsare read in the display CRS — which for such a figure means array indices.set_bounds(None)fits the array, andset_bounds((0, 0, 4, 3))frames columns 0-4 and rows 0-3. Geographic bounds would frame empty axes, and there is nothing to tell them apart by.
Nodata in a bare array is a masked array. There is no sidecar to carry a no_data_value, so
np.ma.masked_equal(grid, -9999) (or NaN in the values) is how a cell says it has none, and
those cells are left blank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids |
required |
band
|
int
|
1-based band index to draw — the Core keyword, named here rather than reached through
|
DEFAULT_BAND
|
cmap
|
str | None
|
Colormap name, or |
None
|
limits
|
tuple[float, float] | None
|
The colour domain as |
None
|
opacity
|
float | None
|
How opaque the field is, in |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: Five more of those keywords decide the colour domain and what falls outside it, and
they are declared in
|
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map, so a figure reads as one expression — measured: |
Self
|
|
Self
|
canonical note the other builders point at.** |
Self
|
The decoration methods chain too, as of round 1's L6: |
Self
|
|
Self
|
annotated |
Self
|
(measured). The deliberate |
Self
|
in this list rather than beside its own method: |
Self
|
meth: |
Self
|
|
Self
|
it draws onto the axes while registering no layer, so — measured on a map carrying one |
Self
|
|
Self
|
|
Self
|
layer rather than a layer of its own. |
Self
|
It returned the |
Self
|
package's own contract: |
Self
|
|
Self
|
declared chainable — and this tier handed back the engine's object instead. That contract, |
Self
|
not the other tiers, is what the change answers to: the web and interactive builders do |
Self
|
answer that way ( |
Self
|
|
Self
|
|
Self
|
|
Self
|
Each hands back the |
Self
|
the layer. So this tier was not the only one returning the engine's object, and the 3-D row is |
Self
|
still open. |
Self
|
|
Self
|
does not measure return values, which is why the divergence went unnoticed: the same line |
Self
|
chained on two tiers and raised |
Self
|
checked by |
Self
|
annotation, and a body that really hands back |
Self
|
The artist is still reachable, through |
Self
|
meth: |
Self
|
to return — the layer drawn last — and |
Self
|
to keep a stable handle on a layer's artist in a figure of several. |
Self
|
An off-limb layer is now read from the figure rather than from a |
Self
|
data lies entirely outside what the display CRS shows draws nothing and is absent from |
Self
|
attr: |
Self
|
meth: |
Self
|
tier gives, and testable without a return value. An off-limb draw still renders an empty frame |
Self
|
rather than raising. |
Raises:
| Type | Description |
|---|---|
TypeError
|
when |
ValueError
|
when |
Examples:
- Draw a bare grid, and read back where its image was placed:
- A diverging field: the centre asks for symmetric limits and a diverging ramp, and the
extreme colours say what a clipped value and a nodata cell are drawn as:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from matplotlib.colors import to_hex >>> from digitalearth.static import Map >>> anomaly = np.array([[-3.0, 0.0], [4.0, 8.0]]) >>> with Map() as m: ... _ = m.field(anomaly, name="anom", center=0.0, over="#ff0000", missing="#cccccc") ... m.artist("anom").get_clim() ... m.artist("anom").get_cmap().name ... to_hex(m.artist("anom").get_cmap().get_over()) (-8.0, 8.0) 'viridis-diverging' '#ff0000' - A centre the band does not straddle keeps the sequential ramp rather than drawing one arm of a diverging one, and says so in the log:
- Classify a raster into four equal-interval classes, and read back the edges it was cut at:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from pyramids.dataset import Dataset >>> from digitalearth.static import Map >>> ds = Dataset.read_file("examples/data/acc4000.tif") >>> with Map(crs=ds.epsg) as m: ... _ = m.field(ds, scheme="equal_interval", k=4) ... m.last_breaks [0.0, 22.0, 44.0, 66.0, 88.0] - Draw a band of class codes as categories, and read the key's labels — one per code:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import Map >>> landcover = np.array([[1.0, 1.0, 2.0], [3.0, 3.0, 2.0]]) >>> with Map() as m: ... _ = m.field(landcover, scheme="categorical") ... _ = m.legend() ... [label.get_text() for label in m.ax.get_legend().get_texts()] ['1', '2', '3'] - A band of fractional values is a magnitude, so the categorical scheme refuses it:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import Map >>> with Map() as m: ... m.field(np.array([[0.5, 1.0]]), scheme="categorical") # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: scheme='categorical' needs integer class codes ...
Source code in src/digitalearth/static/builders/raster.py
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 | |
contours(dataset, *, levels=None, interval=None, filled=False, hatches=None, hatch_color=None, name=None, visible=True, **kwargs)
#
Trace iso-value lines through a raster band, or fill between them.
One method for both renders, which is what the Tier-2 contract declares and what the web and
interactive tiers offer. This tier had two — contour and contourf — so filled= meant
nothing here and a script moving between tiers had to know which of the two to write. Neither
spelling survives: filled= is the argument that picks the render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
levels
|
Any
|
The iso-values to trace — an int (a count) or a sequence of values. |
None
|
interval
|
float | None
|
Spacing between levels — one level every N, in the band's own units. Resolved
against the band's range when it is drawn, so only the multiples inside the data are
traced. Give at most one of this or |
None
|
filled
|
bool
|
|
False
|
hatches
|
Sequence[str | None] | None
|
A hatch pattern per band between |
None
|
hatch_color
|
str | None
|
The colour of the hatch strokes. |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See :meth: |
Self
|
the return value is the map rather than the artist. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- A significance overlay: hatch where p < 0.05, leave the rest of the map as it is, and key it.
labels=carries one label per bandlevels=declares — two here — while the key draws only the bands the map actually marks and the data reaches, which is the first. The count therefore comes from the call and not from the raster, so a recordedlabels=keeps working when the data stops reaching a band:>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth import Map >>> p = Dataset.from_array( ... arr=np.array([[0.01, 0.3], [0.02, 0.6]]), ... geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326), ... no_data_value=-9999.0, ... ) >>> m = Map(crs=4326) >>> _ = m.contours( ... p, levels=[0, 0.05, 1], filled=True, hatches=["///", ""], fill=False, name="sig" ... ) >>> list(m.artist("sig").hatches) ['///', ''] >>> legend = m.legend( ... "sig", labels=["p < 0.05", "p >= 0.05"] ... ).ax.get_legend() >>> [t.get_text() for t in legend.get_texts()], legend.legend_handles[0].get_hatch() (['p < 0.05'], '///') >>> m.close() - Each of the three band keywords is refused where it would have no effect, by name — a line
render has no bands to hatch, and the other two have nothing to hatch with:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth import Map >>> p = Dataset.from_array( ... arr=np.array([[0.01, 0.3], [0.02, 0.6]]), ... geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326), ... no_data_value=-9999.0, ... ) >>> m = Map(crs=4326) >>> for bands in ({"hatches": ["///", ""]}, {"filled": True, "hatch_color": "black"}): ... try: ... m.contours(p, levels=[0, 0.05, 1], **bands) ... except ValueError as error: ... print(str(error)[:67]) contours() hatches the bands between levels, which only a filled re contours(hatch_color=) colours the hatch strokes and there are none >>> m.close()
Source code in src/digitalearth/static/builders/raster.py
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | |
pcolormesh(dataset, *, name=None, visible=True, **kwargs)
#
Render a raster as a quadrilateral mesh (ArrayGlyph kind="pcolormesh").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See :meth: |
Self
|
the return value is the map rather than the artist. |
Raises:
| Type | Description |
|---|---|
ValueError
|
from |
Source code in src/digitalearth/static/builders/raster.py
block(dataset, *, name=None, visible=True, **kwargs)
#
Render a raster as a filled cell mesh — currently an alias of :meth:pcolormesh.
block is meant for discrete per-cell rectangles aligned to cell edges. cleopatra's
pcolormesh path accepts cell-centre coordinates only (it rejects edge arrays of length
n + 1), so true edge-aligned blocks need an upstream cleopatra option; until that lands block
draws the same filled mesh as :meth:pcolormesh. It is kept as a distinct, stable entry point so
callers and examples can switch to true blocks transparently once cleopatra supports them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See :meth: |
Self
|
the return value is the map rather than the artist. |
Raises:
| Type | Description |
|---|---|
ValueError
|
from |
Source code in src/digitalearth/static/builders/raster.py
rgb_composite(dataset, bands=DEFAULT_COMPOSITE_BANDS, *, mask_nodata=True, limits=None, name=None, visible=True, **opts)
#
Render three raster bands as a true/false-colour RGB image (ArrayGlyph RGB path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A multiband pyramids |
required |
bands
|
Sequence[int]
|
Three 1-based band indices mapped to R, G, B. Defaults to |
DEFAULT_COMPOSITE_BANDS
|
mask_nodata
|
bool
|
When |
True
|
limits
|
ChannelLimits | None
|
Optional frozen |
None
|
**opts
|
Any
|
Styling kwargs, filtered to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See :meth: |
Self
|
the return value is the map rather than the artist. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- Composite three bands of a multiband raster into one RGB image:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> ds = Dataset.read_file("examples/data/acc4000.tif") >>> base = np.nan_to_num(ds.read_array(band=0).astype("float32")) >>> rgb = Dataset.from_array(arr=np.stack([base, base, base]), ... geo_ref=GeoReference(geo=ds.geotransform, epsg=ds.epsg)) >>> m = Map(crs=rgb.epsg) >>> _ = m.rgb_composite(rgb) >>> len(m.ax.images) 1 >>> m.close() - Frozen
limitsreplace the per-call stretch: a white point far above the data renders it black, which is what holds a sequence of frames on one scale:>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> ds = Dataset.read_file("examples/data/acc4000.tif") >>> base = np.nan_to_num(ds.read_array(band=0).astype("float32")) >>> rgb = Dataset.from_array(arr=np.stack([base, base, base]), ... geo_ref=GeoReference(geo=ds.geotransform, epsg=ds.epsg)) >>> m = Map(crs=rgb.epsg) >>> _ = m.rgb_composite(rgb, limits=[(0.0, 1e6)] * 3) >>> round(float(np.nanmax(m.ax.images[-1].get_array())), 3) 0.0 >>> m.close()
See Also
hsv_composite: The same three bands read as hue/saturation/value instead.
digitalearth.base.stretch.channel_limits: Derives the limits this accepts.
Source code in src/digitalearth/static/builders/raster.py
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 | |
points(features, *, column=None, scheme=None, k=5, cmap=None, size=None, opacity=None, size_column=None, name=None, visible=True, **opts)
#
Plot a pyramids FeatureCollection of points, coloured and sized by a column (ScatterGlyph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str | None
|
The column whose values colour the points; |
None
|
scheme
|
Any | None
|
How |
None
|
k
|
int
|
Number of classes a named |
5
|
cmap
|
Any | None
|
The colormap the points are coloured through; |
None
|
size
|
float | None
|
The marker's visual size, spelled the same way on every backend (#251); |
None
|
opacity
|
float | None
|
How opaque the markers are, in |
None
|
size_column
|
str | None
|
Optional column name whose values set the per-point marker size. Pair it with
|
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Further |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
ValueError
|
if |
Source code in src/digitalearth/static/builders/vector.py
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 | |
grid_points(dataset, *, name=None, visible=True, **opts)
#
Plot raster cell centres as points coloured by value (pyramids to_xyz → ScatterGlyph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Styling kwargs, filtered to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Examples:
- Scatter the raster's valid cell centres and count the resulting layer:
Raises:
| Type | Description |
|---|---|
TypeError
|
when |
Source code in src/digitalearth/static/builders/vector.py
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 | |
grid_cells(dataset, band=DEFAULT_BAND, *, name=None, visible=True, **opts)
#
Draw raster cells as value-coloured polygons (pyramids to_geodataframe → PolygonGlyph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
band
|
int
|
1-based band whose values colour the cells. |
DEFAULT_BAND
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
The caller's own engine keywords, handed to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
TypeError
|
when |
ValueError
|
from |
Examples:
- Draw one polygon per raster cell and confirm the count equals rows*columns:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from pyramids.dataset import Dataset >>> from digitalearth.static import Map >>> ds = Dataset.read_file("examples/data/acc4000.tif") >>> m = Map(crs=ds.epsg) >>> _ = m.grid_cells(ds, name="cells") >>> cells = m.artist("cells") >>> len(cells.get_paths()) == ds.rows * ds.columns True >>> m.close()
Source code in src/digitalearth/static/builders/vector.py
2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 | |
lines(features, *, column=None, scheme=None, k=5, cmap=None, width=None, color=None, opacity=None, name=None, visible=True, **opts)
#
Draw line features — rivers, roads, tracks, reach networks (pyramids lines → FlowGlyph).
The Core contract's lines, with the web tier's keywords: a constant colour, or a colour per
feature from column (classified by scheme/k), and a width that is either one number or a
column. MultiLineString features draw one path per part, each carrying its feature's values.
:meth:sankey draws the same geometry as a flow map, with flow defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str | None
|
Numeric column whose value colours each line; |
None
|
scheme
|
Any | None
|
A classification scheme cutting |
None
|
k
|
int
|
Number of classes for |
5
|
cmap
|
Any | None
|
The colormap |
None
|
width
|
float | str | None
|
Line width in points — a positive number — or the name of a numeric column whose values
scale each line's width (between |
None
|
color
|
Any | None
|
The colour of every line when |
None
|
opacity
|
float | None
|
Layer opacity, 0 transparent to 1 opaque. |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Further |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
KeyError
|
if |
Examples:
- Colour reaches by discharge, classified into three classes, with one width:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import LineString >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> reaches = FeatureCollection(gpd.GeoDataFrame( ... {"discharge": [10.0, 40.0, 25.0]}, ... geometry=[LineString([(0, 0), (1, 1)]), LineString([(1, 1), (2, 1)]), ... LineString([(2, 1), (3, 2)])], ... crs="EPSG:4326", ... )) >>> with Map(crs=4326) as m: ... _ = m.lines(reaches, column="discharge", scheme="equal_interval", k=3, width=2.0) ... lc = m.artist() ... lc.get_array().tolist(), sorted({float(w) for w in lc.get_linewidths()}) ... m.figure_spec.layers.get(m.layer_ids[-1]).kind ([10.0, 40.0, 25.0], [2.0]) 'lines' - One colour, widths scaled by a column:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import LineString >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> roads = FeatureCollection(gpd.GeoDataFrame( ... {"lanes": [1, 4]}, ... geometry=[LineString([(0, 0), (1, 0)]), LineString([(0, 1), (1, 1)])], ... crs="EPSG:4326", ... )) >>> with Map(crs=4326) as m: ... _ = m.lines(roads, width="lanes", color="dimgray") ... widths = m.artist().get_linewidths() >>> bool(widths[1] > widths[0]) True - A width a line cannot have, a column name under
color=, and a text column undercolumn=are each refused by name — and the colour refusal points at the keyword that does take a column's name:>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import LineString >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> roads = FeatureCollection(gpd.GeoDataFrame( ... {"name": ["a", "b"], "lanes": [1.0, 4.0]}, ... geometry=[LineString([(0, 0), (1, 0)]), LineString([(0, 1), (1, 1)])], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> for wrong in ({"width": -2.0}, {"color": "lanes"}, {"column": "name"}): ... try: ... m.lines(roads, **wrong) ... except ValueError as error: ... print(str(error)[:63]) Map.lines() needs width= as a positive number of points, or the Map.lines() needs color= as one matplotlib colour for every lin Map.lines() needs column='name' to name a column of numbers, an >>> m.close() - A column name these features do not carry is named under the keyword it was given under,
with the columns they do carry listed:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import LineString >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> roads = FeatureCollection(gpd.GeoDataFrame( ... {"name": ["a", "b"], "lanes": [1.0, 4.0]}, ... geometry=[LineString([(0, 0), (1, 0)]), LineString([(0, 1), (1, 1)])], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> for wrong in ({"column": "flow"}, {"width": "order"}): ... try: ... m.lines(roads, **wrong) ... except KeyError as error: ... print(error.args[0]) Map.lines(): column='flow' is not a property of these features; available: ['lanes', 'name'] Map.lines(): width='order' is not a property of these features; available: ['lanes', 'name'] >>> m.close()
See Also
sankey: the same geometry drawn as a flow map.
Source code in src/digitalearth/static/builders/vector.py
4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 | |
polygons(features, *, column=None, scheme=None, k=5, cmap=None, opacity=None, name=None, visible=True, **opts)
#
Draw polygons — outlines, or a fill coloured by column (pyramids FeatureCollection).
Without column this draws outlines with no fill (PolygonGlyph outline mode); with one it
fills them coloured by that attribute, the same render :meth:choropleth draws — the Core declares
polygons with the full colour vocabulary, so the two are one builder here as on the other tiers
(#332).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str | None
|
The column whose values fill the polygons; |
None
|
scheme
|
Any | None
|
How |
None
|
k
|
int
|
Number of classes a named |
5
|
cmap
|
Any | None
|
The colormap the fill is drawn with; |
None
|
opacity
|
float | None
|
How opaque the layer is, in |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Styling kwargs, filtered to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
KeyError
|
if |
Source code in src/digitalearth/static/builders/vector.py
3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 | |
choropleth(features, column, *, scheme=None, k=5, cmap=None, opacity=None, name=None, visible=True, **opts)
#
Fill polygons coloured by a feature attribute (pyramids FeatureCollection → PolygonGlyph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str
|
Name of the column whose values colour the polygons — numeric for a continuous or
graduated scale, or any nominal labels (strings, region codes, …) under
|
required |
scheme
|
Any | None
|
How the values are classified. |
None
|
k
|
int
|
Number of classes a named |
5
|
opacity
|
float | None
|
How opaque the fill is, in |
None
|
cmap
|
Any | None
|
The colormap the fill is drawn with, forwarded to |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Styling kwargs forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
Examples:
- Colour buffered point features by their
fidcolumn and count the drawn polygons:>>> import matplotlib >>> matplotlib.use("Agg") >>> from pyramids.feature import FeatureCollection >>> from digitalearth.static import Map >>> fc = FeatureCollection.read_file("tests/data/points.geojson") >>> fc["geometry"] = fc.geometry.buffer(500.0) >>> m = Map(crs=fc.epsg) >>> _ = m.choropleth(fc, column="fid", name="zones") >>> len(m.artist("zones").get_paths()) >= len(fc) True >>> m.close() - Colour by an unordered attribute — one colour per distinct class, keyed by a swatch legend:
>>> fc["zone"] = ["urban", "rural"] * (len(fc) // 2) + ["urban"] * (len(fc) % 2) >>> m = Map(crs=fc.epsg) >>> _ = m.choropleth(fc, column="zone", scheme="categorical", name="zoning") >>> from matplotlib.colors import BoundaryNorm >>> norm = m.artist("zoning").norm >>> isinstance(norm, BoundaryNorm) # discrete class codes, not a continuous scale True >>> [t.get_text() for t in m.layers[-1][0].category_legend.get_texts()] ['rural', 'urban'] >>> m.close()
Source code in src/digitalearth/static/builders/vector.py
3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 | |
hexbin(features, column=None, *, reduce=DEFAULT_HEXBIN_REDUCE, gridsize=50, min_count=None, name=None, visible=True, **opts)
#
Aggregate points onto a hexagonal lattice and colour each cell (pyramids points → HexbinGlyph).
The discrete counterpart of :meth:kde: with no column each cell is coloured by how many points
fell in it, and with one by the reduce of their values — a number read straight off the colour
key, with none of the over-plotting a dense scatter has. The points are reprojected to the display
CRS first and the lattice is laid there, so the cells are regular on the map rather than equal-area
on the ground. The layer is a choropleth of the aggregate, as :meth:quadtree's is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str | None
|
Numeric column aggregated per cell, or |
None
|
reduce
|
Any
|
How a cell's values aggregate: |
DEFAULT_HEXBIN_REDUCE
|
gridsize
|
Any
|
Hexagons across the binned window — a whole number, or an |
50
|
min_count
|
int | None
|
Leave out cells with fewer points than this, as a whole number of points.
|
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Further |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
KeyError
|
if |
Examples:
- Count the points per cell; three coincident points are one cell holding 3:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Point >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> wells = FeatureCollection(gpd.GeoDataFrame( ... {"depth": [2.0, 4.0, 6.0, 100.0]}, ... geometry=[Point(0, 0), Point(0, 0), Point(0, 0), Point(8, 8)], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> _ = m.hexbin(wells, gridsize=4, name="counts") >>> sorted(m.artist("counts").get_array().tolist()) [1.0, 3.0] >>> m.close() - Aggregate a column instead; the origin cell is the mean of 2, 4 and 6:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Point >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> wells = FeatureCollection(gpd.GeoDataFrame( ... {"depth": [2.0, 4.0, 6.0, 100.0]}, ... geometry=[Point(0, 0), Point(0, 0), Point(0, 0), Point(8, 8)], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> _ = m.hexbin(wells, "depth", reduce="mean", gridsize=4, name="depths") >>> sorted(m.artist("depths").get_array().tolist()) [4.0, 100.0] >>> m.figure_spec.layers.get(m.layer_ids[-1]).symbology.props["via"] 'hexbin' >>> m.close() - A lattice nothing could be binned onto is refused here, naming the argument, rather than
surfacing as matplotlib arithmetic several frames down:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Point >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> wells = FeatureCollection(gpd.GeoDataFrame( ... {"depth": [2.0, 4.0]}, ... geometry=[Point(0, 0), Point(8, 8)], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> for lattice in ({"gridsize": 0}, {"gridsize": 4, "min_count": -1}): ... try: ... m.hexbin(wells, **lattice) ... except ValueError as error: ... print(error) hexbin() needs gridsize= as a whole number >= 1; got 0 hexbin() needs min_count= as a whole number >= 0; got -1 >>> m.close() - A
columnthese features do not carry is named with the columns they do, and one that holds text is refused for what the reducer cannot do with it:>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Point >>> from pyramids.feature import FeatureCollection >>> from digitalearth import Map >>> wells = FeatureCollection(gpd.GeoDataFrame( ... {"depth": [2.0, 4.0], "site": ["north", "south"]}, ... geometry=[Point(0, 0), Point(8, 8)], ... crs="EPSG:4326", ... )) >>> m = Map(crs=4326) >>> try: ... m.hexbin(wells, "dpeth", gridsize=4) ... except KeyError as error: ... print(error.args[0]) hexbin(): column='dpeth' is not a property of these features; available: ['depth', 'site'] >>> try: ... m.hexbin(wells, "site", gridsize=4) ... except ValueError as error: ... print(error) hexbin() needs column='site' to name a column of numbers, and it holds str values that are not numbers >>> m.close()
See Also
kde: the smoothed density of the same points. quadtree: points aggregated into adaptive square cells.
Source code in src/digitalearth/static/builders/vector.py
3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 | |
quiver(u_dataset, v_dataset, *, name=None, visible=True, **kwargs)
#
Draw a vector field as arrows (VectorGlyph kind="quiver").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_dataset
|
Any
|
pyramids |
required |
v_dataset
|
Any
|
pyramids |
required |
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
ValueError
|
from |
FileNotFoundError
|
when a component's path names nothing. |
KeyError
|
when no resolver is registered for a component's URL scheme. |
Source code in src/digitalearth/static/builders/vector.py
streamplot(u_dataset, v_dataset, *, name=None, visible=True, **kwargs)
#
Draw a vector field as streamlines (VectorGlyph kind="streamplot").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_dataset
|
Any
|
pyramids |
required |
v_dataset
|
Any
|
pyramids |
required |
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
ValueError
|
from |
FileNotFoundError
|
when a component's path names nothing. |
KeyError
|
when no resolver is registered for a component's URL scheme. |
Source code in src/digitalearth/static/builders/vector.py
labels(features, column, *, text_size=DEFAULT_LABEL_TEXT_SIZE, color=DEFAULT_LABEL_COLOR, halo_color=DEFAULT_LABEL_HALO_COLOR, halo_width=DEFAULT_LABEL_HALO_WIDTH, offset=None, crs=None, name=None, visible=True, **opts)
#
Label every feature with the text in column — one string per feature, from an attribute.
The static third of order 27's text layers (ST-16, #345). WebMap.labels shipped first and the
labels kind was registered with it, so a caller could label a collection on a web map and not on a
static one; :meth:~digitalearth.static.builders.decoration.DecorationMixin.text is no substitute, since
it places one string at one coordinate.
The keywords are WebMap.labels's wherever the two tiers can mean the same thing, which is the point
of the Core contract — one spelling per concept:
text_size,color— the same, with the same defaults, so one call gives one picture. It istext_sizeand neversize:sizeis the visual size of a marker on every other builder, and a keyword cannot mean both. matplotlib's ownfontsize/sizeare refused here rather than quietly overwritten.halo_color,halo_width— MapLibre's text halo is matplotlib'spath_effectsstroke: the same idea, a different spelling, so the keywords carry across and this builder builds the stroke.halo_width=0draws no halo, and a caller's ownpath_effects=replaces it.offset— carried, and converted. MapLibre measures it in ems with y pointing down; matplotlib in points with y pointing up. Both are resolved in the drawer, sooffset=(0, -1.2)lifts a label off its point by 1.2 of its own text size on either tier.allow_overlap— not carried, and refused rather than accepted. It asks MapLibre's symbol layer to keep colliding labels; matplotlib has no collision index to ask, and draws every label wherever it lands. The tier declares that underlabel_collisionin :data:~digitalearth.static.capabilities.CAPABILITIES, and the refusal quotes that declaration, so the answer a caller gets and the answer a dispatcher reads are one sentence. A crowded column is thinned by filtering the features before drawing them.crs— the Core keyword for this name, and here it has a job the web tier has no use for: it says what a collection declaring no CRS is measured in, which is the one case pyramids cannot reproject. It is never ignored — against a collection with its own CRS it either agrees or is refused (see :func:_labelled_features).
Points are labelled at the point; a line or a polygon at its centroid, which is the fallback every other reader of vector geometry in this package uses. A feature whose value is missing, and one on the far side of a globe, are simply not labelled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str
|
The attribute the label text is read from. Checked when the features are opened, because a path-referenced layer has none to check at the call. |
required |
text_size
|
float
|
Text size in points. Named for the text rather than |
DEFAULT_LABEL_TEXT_SIZE
|
color
|
str
|
Text colour. |
DEFAULT_LABEL_COLOR
|
halo_color
|
str
|
Colour of the outline drawn behind the glyphs, which is what keeps a label legible over a raster field or a basemap. |
DEFAULT_LABEL_HALO_COLOR
|
halo_width
|
float
|
Halo width in points; |
DEFAULT_LABEL_HALO_WIDTH
|
offset
|
Any | None
|
|
None
|
crs
|
Any
|
What the features' coordinates are measured in, for a collection that declares none.
|
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**opts
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The drawn artist is reached with |
Self
|
meth: |
Self
|
drawn, or |
Self
|
drew nothing, so it is absent from the figure and refused there. See |
Self
|
meth: |
Self
|
map rather than the artist (ST-20). |
Raises:
| Type | Description |
|---|---|
KeyError
|
when |
TypeError
|
when |
ValueError
|
for a |
Examples:
- Label each feature with its
fid, and count the annotations drawn:>>> import matplotlib >>> matplotlib.use("Agg") >>> from pyramids.feature import FeatureCollection >>> from digitalearth.static import Map >>> places = FeatureCollection.read_file("tests/data/points.geojson") >>> with Map(crs=places.epsg) as canvas: ... _ = canvas.labels(places, "fid", text_size=9.0, name="names") ... len(canvas.artist("names")) == len(places) True
See Also
digitalearth.static.builders.decoration.DecorationMixin.text: one string at one coordinate. digitalearth.static.builders.decoration.DecorationMixin.annotate: one string, with an arrow to a point.
Source code in src/digitalearth/static/builders/vector.py
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 | |
set_bounds(bounds=None, *, padding=0.0)
#
Frame the figure on a region, or on everything it draws — the Core contract's framing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Bounds | Sequence[float] | None
|
A :class:
|
None
|
padding
|
float
|
Breathing room around the frame, as a fraction of its own span — |
0.0
|
Returns:
| Type | Description |
|---|---|
Self
|
This map, so the call chains ( |
Self
|
declares |
Self
|
static, interactive and web tiers; the 3-D tier declares the name pending, in |
Self
|
|
Self
|
box; the Core-spelled set_bounds(bounds, padding) is not yet adopted here"*. That tier frames to |
Self
|
an extent through |
Self
|
this shape, so |
Self
|
|
Self
|
one. The spelling this tier used to carry returned |
Self
|
raised on another. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the sequence form does not hold exactly four values; if |
Warns:
| Type | Description |
|---|---|
UserWarning
|
naming every degree a labelled graticule's re-label cannot place in the view
this call has just framed — |
Notes
A flipped pair is honoured in the sequence form: an east west of its west inverts the
x axis, which is how matplotlib expresses invert_xaxis through the limits, and padding
grows such an axis outwards rather than inwards. :attr:viewport reports the region either way
round: a Bounds refuses corners the wrong way round, and the direction an axis runs in is a
property of the axes rather than of the region shown.
The sequence used to be read as matplotlib's own [xmin, xmax, ymin, ymax], which is the order
the axes limits are set in and the order the method carried under its old name. It was the only
spelling in the package that read four bare numbers that way, so one call framed two different
rectangles across the 2-D tiers; the matplotlib ordering is reachable from Bounds alone now,
through :meth:~digitalearth.base.spec.bounds.Bounds.as_mpl.
A graticule is re-cut and re-labelled against the view this call leaves behind, because its
lines are cut to the view and a degree label is positioned in the view it is read off, and a
flat map has no render-time pass to revisit either (:meth:_relabel_graticule, reviews R2-M2
and #393). The lines are re-cut even when the grid is bare (labels=False), since they depend
on the view whether or not they carry degrees. This is therefore the one call that redraws a
graticule layer without graticule() being written, so it carries that method's placement
warning — see Warns.
What :attr:viewport reports is read back off the axes once the limits are set, so it is the
rectangle the figure is holding rather than the one that was asked for. The two differ for a frame
of zero span — a fit onto a single point, or padding=-0.5, the bottom of the legal range:
matplotlib refuses a singular limit and expands it (by 5% of the value, warning as it goes), and
the region reported is that expanded one. It is read at framing time and not re-read, so a later
builder that autoscales the axes moves the picture without moving what this reports.
Examples:
- A rectangle in another CRS is converted, so the frame lands where the data is:
- The bare sequence is
(west, south, east, north), in the display CRS, and the view reports it back in the order it was written:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> m = Map(crs=3857) >>> _ = m.set_bounds([0.0, 0.0, 100.0, 50.0]) >>> [float(v) for v in m.ax.get_xlim()], [float(v) for v in m.ax.get_ylim()] ([0.0, 100.0], [0.0, 50.0]) >>> m.viewport.bounds.as_bbox() [0.0, 0.0, 100.0, 50.0] >>> m.close() paddinggrows the frame by a fraction of its span:
Source code in src/digitalearth/static/builders/projection.py
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 | |
set_domain(domain=None)
#
Set the axes extent from a named region or bbox, reprojected to the display CRS via pyramids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
DomainLike | None
|
A registered region name (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
This map, so the call chains like :meth: |
Self
|
path answers the map as well**: a call with nothing to resolve frames nothing, and a chain |
Self
|
must survive it (L6). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a caller-supplied bbox has its corners the wrong way round — including one crossing the antimeridian, which a single rectangle cannot express. |
Examples:
- In a geographic CRS the axes limits equal the named region's bounds:
Source code in src/digitalearth/static/builders/projection.py
graticule(lon_step=None, lat_step=None, *, spacing=None, labels=None, name=None, visible=None)
#
Add a lon/lat graticule to the map, with its degrees labelled.
A second call replaces the first — the map holds one set of graticule lines, so it draws one
graticule — and the description follows: the layer keeps its id and its place in the tree and only
what the replacing call named changes. Describing the second call as a second layer would say the
map draws two grids where it draws one — and that is also why a name on a replacing call
names nothing: the layer already has its id, and taking a new one would break every caller holding
the old one.
One rule for the rest of the arguments: a replacing call keeps every option it does not name.
A call that names a spacing is asking for a spacing, not for a hidden grid to come back
(visible, review R-L5), nor for the degrees of a deliberately bare grid to come back
(labels), nor for the step it did not mention to be re-cut at the default (lon_step /
lat_step) — the last two used to fall back to their construction defaults, which relabelled
and re-cut grids in silence (round 1, M7). spacing is the one argument that overrides what the
grid carries without being asked twice, because it names both steps by definition. The frame still
outranks all of it: labels=True on a globe is refused whatever the grid it replaces carried.
Which frame draws it, and when. On a flat map — the default — the lines and their labels go on
the axes as this call runs. On a globe=True map they are drawn later, by the projection frame
(render()/save()/show()), because a globe's grid has to be clipped at the limb with
everything else. Before #221 the flat map had no such pass, so this call computed a grid, stored
it, and drew nothing at all while the figure described a layer that was drawn.
A later framing call re-cuts and re-labels it. The lines are cut to the view and the degrees
are placed in it, so a grid drawn before :meth:set_bounds, :meth:set_domain or
:meth:set_global is redrawn by that call against the view it leaves behind
(:meth:_relabel_graticule) — the lines are re-cut to the new region and the labels re-placed in
it (#393). Until #393 the lines spanned the world whatever the view, so only the labels moved; now a
fine grid on a small region draws the handful of lines that region holds rather than the world's.
Until R2-M2 the labels were placed once: graticule(spacing=30.0) followed by
set_domain("europe") left all 18 degrees outside the axes and off the canvas without a word,
and the reverse order of the same two calls drew three. A bare (labels=False) grid is re-cut
too — its lines depend on the view even though it carries no degrees — but its degrees do not come
back, the rule a replacing call here already follows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon_step
|
float | None
|
Meridian spacing in degrees; |
None
|
lat_step
|
float | None
|
Parallel spacing in degrees, the same way round. |
None
|
spacing
|
float | None
|
One step for both, for a caller who wants a square grid; it overrides the two
above, and warns when it does, because a call that names all three has had two of
its own arguments thrown away (review R2-L3). The same keyword the web and
interactive tiers take, so one call draws one grid on every tier that draws a graticule
at all (#324). The values are each engine's own: this tier generates its meridians,
so any positive step draws, and so does the web tier — while the interactive tier draws
Natural Earth's pre-cut layers and honours only |
None
|
labels
|
bool | None
|
Whether each line carries its degree — |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label on the call that
creates it; |
None
|
visible
|
bool | None
|
Whether the graticule is drawn. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self
|
This map, so the call chains like every other layer builder on the tier |
|
Self
|
( |
|
Self
|
makes it a builder by every other test here; it used to hand back nothing, which broke the |
|
Self
|
chain on the one tier whose |
|
Self
|
The grid itself is reached by id, and a graticule is the layer where the two spellings differ. |
|
Self
|
|
|
Self
|
polylines, 18 of them at the default spacing on an unframed (world) view, as |
|
Self
|
because that is this drawer's value, and it answers that way even on a globe whose lines are not |
|
Self
|
on the axes yet. What is on the axes is |
|
Self
|
different shape per frame. A flat map carries one |
|
Self
|
|
|
Self
|
framed view cuts the lines to the region it holds and places a degree on each line it can, |
|
Self
|
whichever order the framing call and this one are written in. Measured on |
|
orders |
Self
|
|
Self
|
``` |
|
Self
|
unframed, spacing=30 polylines=18 LineCollection=1 Text=18 |
|
Self
|
framed THEN graticule, spacing=30 polylines= 9 LineCollection=1 Text=6 |
|
Self
|
graticule THEN framed, spacing=30 polylines= 9 LineCollection=1 Text=6 |
|
Self
|
unframed, spacing=60 polylines= 9 LineCollection=1 Text=10 |
|
Self
|
framed THEN graticule, spacing=60 polylines= 5 LineCollection=1 Text=3 |
|
Self
|
graticule THEN framed, spacing=60 polylines= 5 LineCollection=1 Text=3 |
|
Self
|
labels=False, unframed polylines=18 LineCollection=1 |
|
Self
|
labels=False, framed (either order) polylines= 9 LineCollection=1 |
|
Self
|
``` |
|
Self
|
("framed" is |
|
Self
|
grid drawn before it to the same view a grid drawn after it is cut to. Before #393 the polyline |
|
Self
|
counts did not clip — a framed grid carried the world's 18 (or 9) lines — and before R2-M2 the |
|
Self
|
two orders' label counts differed, the second row of each pair carrying the first row's labels, |
|
Self
|
placed against a view the figure had already left. |
|
Self
|
A globe's grid is instead drawn by |
|
Self
|
polyline (measured: 18, and 0 artists before |
|
Self
|
on that second list, so both reach every frame's grid. Neither spelling raises for a graticule |
|
Self
|
this call built — the |
Warns:
| Type | Description |
|---|---|
UserWarning
|
when |
Raises:
| Type | Description |
|---|---|
ValueError
|
for |
Exception
|
whatever computing the grid raises, after the description has been put back as it was. A figure must not name a layer that was not drawn, and a refused replacement must not restyle the graticule the map is still drawing (round 2, M1). |
Examples:
- A flat map's grid is one collection, and every line in view carries its degree:
- The lines can be drawn bare:
- A replacing call keeps what it does not name: the grid is re-cut at 60 degrees and stays
bare, and its parallels keep the step only the first call named:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> m = Map(crs=4326) >>> _ = m.set_bounds([-35.0, -5.0, 35.0, 65.0]) >>> _ = m.graticule(lon_step=30.0, lat_step=45.0, labels=False) >>> _ = m.graticule(lon_step=60.0) >>> props = m._layer_tree.get(m._graticule_id).symbology.props >>> (props["lon_step"], props["lat_step"], props["labels"]) (60.0, 45.0, False) >>> len(m.ax.texts) 0 >>> m.close() - A globe draws the grid unlabelled, and refuses
labels=Truerather than dropping them quietly — the defaultlabels=Noneis what lets one line serve both frames:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> globe = Map(crs=4326, globe=True) >>> _ = globe.graticule(spacing=30.0) >>> len(globe.ax.texts) 0 >>> globe.graticule(spacing=30.0, labels=True) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: graticule(labels=True) cannot place degree labels on a globe frame... >>> globe.close() - A degree the frame cannot place is named in a warning, not silently missing: a polar
projection framed on a square puts most meridians' anchors outside the view:
>>> import warnings >>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> m = Map(crs=3413) >>> _ = m.set_bounds([-3.0e6, -3.0e6, 3.0e6, 3.0e6]) >>> with warnings.catch_warnings(record=True) as caught: ... warnings.simplefilter("always") ... _ = m.graticule(spacing=30.0) >>> message = str(caught[0].message) >>> message.split(":")[0] 'graticule() could not place 8 degree label(s)' >>> "150°W" in message, "120°E" in message (True, True) >>> len(m.ax.texts) 6 >>> m.close()
Source code in src/digitalearth/static/builders/projection.py
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 | |
basemap(provider=None, *, api_key=None, preset=None, name=None, visible=True, **kwargs)
#
Add an XYZ-tile basemap to the axes via cleopatra's GeoMixin.add_tiles in the display CRS.
provider is passed through to cleopatra unchanged — a provider name or an
xyzservices.TileProvider — with two additions. The name of a keyed basemap preset (see
:mod:digitalearth.base.basemaps) is resolved here into a configured provider, with its credential
read from the environment and its coverage checked against the map's domain first. And the four
cross-tier basemap names (:data:~digitalearth.base.basemaps.DEFAULT_BASEMAP_PROVIDER among them)
are translated into the xyzservices paths that request the same tiles the interactive and web
tiers do — including when provider is omitted, which means the shared default here just as it
does there, rather than cleopatra's own OpenStreetMap.Mapnik (#247).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
Any
|
A cleopatra/ |
None
|
api_key
|
str | None
|
Credential for a keyed preset; |
None
|
preset
|
dict | None
|
The keyed preset's own keywords, as a dict (for NICFI: |
None
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). What :meth: |
Self
|
layer's id is the axes, because cleopatra's |
Self
|
back rather than naming what it added (its own |
Self
|
same axes, for chaining"*) — the same situation as the Natural-Earth layers on a flat map, and |
Self
|
the same wording. The tile |
Self
|
meth: |
Self
|
meth: |
Self
|
(round 2, M5 — the claim this replaces said |
Self
|
|
Self
|
engine). Tiles that cannot be fetched raise rather than answering |
Self
|
dropped from the description with them. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when a keyed preset is unknown, its credential is unavailable, when a |
TypeError
|
when a preset keyword is missing or misspelled, naming the preset and its keywords. |
Examples:
- A keyed preset resolves its own provider and credential:
- A preset keyword passed loose is refused by name, and nothing is described:
- Tiles need a framed extent to cover, so a basemap on an untouched axes is refused rather than drawn blank:
See Also
digitalearth.base.basemaps: the keyed-preset definitions this resolves.
Source code in src/digitalearth/static/builders/decoration.py
3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 | |
coastlines(resolution='110m', *, name=None, visible=True, **kwargs)
#
Overlay Natural-Earth coastlines (cleopatra.basemap.reference "coastline" layer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
Natural-Earth resolution — |
'110m'
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**kwargs
|
Any
|
Style overrides laid over this layer's Natural-Earth defaults
(:data: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The coastline is reached through |
Self
|
meth: |
Self
|
list of |
Self
|
an orthographic projection); on a flat map the axes, because cleopatra's |
Self
|
draws onto them and hands them back rather than naming what it drew (see |
Self
|
func: |
Examples:
- The reference layers chain, and on a flat map each one's artist is the axes they were drawn onto:
- On a globe the limb splits the layer, so the artist is a list of polylines:
See Also
borders: the same line path for country boundaries. land: the filled counterpart.
Source code in src/digitalearth/static/builders/decoration.py
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 | |
nightshade(when, *, refraction=DEFAULT_REFRACTION, n=DEFAULT_TERMINATOR_SAMPLES, name=None, visible=True, **style)
#
Shade the night side of the day/night terminator at one instant.
The terminator is computed by cleopatra (cleopatra.basemap.solar, a low-precision solar position
good to well under a degree) and projected into the display CRS through pyramids. A night region that
holds a pole is shaded to the pole on a flat map, and a globe shades only its visible hemisphere. On
an axes nothing has framed yet, the map is fitted to the shade and then pulled back inside the
display CRS's own extent, so a projection that places the pole far outside its map (EPSG:3031 puts
it 1.4e10 m out) still frames the region it covers; a framed view is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
when
|
Any
|
The instant, as a |
required |
refraction
|
float
|
The solar altitude, in degrees, that defines the terminator — |
DEFAULT_REFRACTION
|
n
|
int
|
Samples along the terminator. On a globe there is no terminator polygon to sample — the
shade is filled from a display grid — so |
DEFAULT_TERMINATOR_SAMPLES
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**style
|
Any
|
Forwarded to the |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The shade's |
Self
|
is drawn as there — is reached through :meth: |
Self
|
layer's id (round-1 L6). A globe whose visible side holds no night draws nothing and registers |
Self
|
no layer, which is what the |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
TypeError
|
when |
Examples:
- At the March equinox at noon UTC the antimeridian is at midnight and Greenwich at noon:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from datetime import datetime, timezone >>> from digitalearth import Map >>> m = Map(crs=4326) >>> night = m.nightshade( ... datetime(2026, 3, 20, 12, tzinfo=timezone.utc), name="night" ... ).artist("night") >>> [any(p.contains_point(xy) for p in night.get_paths()) for xy in ((170, 0), (0, 0))] [True, False] >>> m.figure_spec.layers.get("night").kind 'nightshade' >>> m.close() - The twilight lines are the same call with another refraction; the figure records it:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> m = Map(crs=3857) >>> _ = m.nightshade("2026-06-21T12:00:00", refraction=-6.0, alpha=0.2) >>> props = m.figure_spec.layers.get(m.layer_ids[-1]).symbology.props >>> props["when"], props["refraction"] ('2026-06-21T12:00:00+00:00', -6.0) >>> m.close() color=Noneis the "not given" matplotlib reads it as, so the default black is drawn rather than the first cycle colour;alpha=0is the invisible shade it asks for:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> with Map(crs=4326) as m: ... shade = m.nightshade( ... "2026-12-21T12:00:00+00:00", color=None, name="black" ... ).artist("black") ... [tuple(round(float(c), 2) for c in face) for face in shade.get_facecolor()] ... faint = m.nightshade( ... "2026-12-21T12:00:00+00:00", alpha=0, name="clear" ... ).artist("clear") ... [tuple(round(float(c), 2) for c in face) for face in faint.get_facecolor()] [(0.0, 0.0, 0.0, 0.35)] [(0.0, 0.0, 0.0, 0.0)]- A refraction above the horizon is refused by name on a globe as on a flat map, so one
keyword answers one way whatever frame it is drawn on:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> for globe in (False, True): ... with Map(crs=4326, globe=globe) as m: ... try: ... m.nightshade("2026-12-21T12:00:00+00:00", refraction=10.0) ... except ValueError as error: ... print(str(error).split(" degrees")[0]) nightshade() needs refraction= in (-90, 0] nightshade() needs refraction= in (-90, 0]
See Also
tissot: the other overlay cleopatra's solar module draws.
Source code in src/digitalearth/static/builders/decoration.py
3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 | |
tissot(lons=None, lats=None, *, radius_m=DEFAULT_TISSOT_RADIUS_M, n=DEFAULT_TISSOT_SAMPLES, name=None, visible=True, **style)
#
Draw Tissot's indicatrices: circles of one ground radius, shown as the projection distorts them.
Each circle is the set of points radius_m from its centre on the sphere (cleopatra's
tissot_circles), projected into the display CRS through pyramids — so a Web Mercator map shows
them swelling toward the poles, and an equal-area one shows them keeping their area. A circle the
projection cannot place whole, such as one on the far side of a globe, is left out. One straddling
the antimeridian is not: it is reconnected across the seam — in degrees on lon/lat axes, in display
coordinates once a projection is involved — so it reads as one ring running past the edge of the
world. Unreconnected it spanned the whole map instead, its vertices landing at both edges at once
(29 of 64 at one edge and the rest at the other, for a 500 km ring at lon 179.5 on Web Mercator).
On an axes nothing has framed yet, the map is fitted to the circles; a framed view is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lons
|
Sequence[float] | None
|
Circle-centre longitudes, in degrees. |
None
|
lats
|
Sequence[float] | None
|
Circle-centre latitudes, in degrees, pairing with |
None
|
radius_m
|
float
|
The ground radius of every circle, in metres (default 500 km). |
DEFAULT_TISSOT_RADIUS_M
|
n
|
int
|
Vertices per circle. |
DEFAULT_TISSOT_SAMPLES
|
name
|
str | None
|
The caller's own name for the layer, used as its id and its label; |
None
|
visible
|
bool
|
Whether the layer is drawn. |
True
|
**style
|
Any
|
Forwarded to the |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This map (chainable). The circles' |
Self
|
meth: |
Self
|
projection could place draws nothing and registers no layer, which is what the |
Self
|
used to answer with said. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when only one of |
Examples:
- On Web Mercator a circle at 60 degrees is drawn twice as wide as one at the equator:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth import Map >>> m = Map(crs=3857) >>> rings = m.tissot( ... [0.0, 0.0], [0.0, 60.0], radius_m=100_000.0, name="rings" ... ).artist("rings") >>> equator, sixty = (np.ptp(p.vertices[:, 0]) for p in rings.get_paths()) >>> round(float(sixty / equator), 1) 2.0 >>> m.close() - With no centres, a world grid is drawn and described as one layer:
- A ring at lon 179.5 stays one 500 km circle on Web Mercator: it runs on past the world's own
eastern edge (
20037508m) instead of being torn in two across it:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> with Map(crs=3857) as m: ... seam = m.tissot( ... lons=[179.5], lats=[0.0], radius_m=500_000.0, name="seam" ... ).artist("seam") ... span = seam.get_paths()[0].vertices[:, 0] ... (round(float(span.min())), round(float(span.max()))) ... bool(span.max() > 20037508.0) (19481444, 20482253) True - An empty centre list is refused by name, because
Nonealready means "every ring was off the map" and the two must not read alike. Either list empty answers the same way: a half-empty pair is what a caller gets when one of two filters came out empty, which is the case the refusal is for:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> with Map(crs=4326) as m: ... for pair in (([], []), ([], [0.0]), ([0.0], [])): ... try: ... m.tissot(lons=pair[0], lats=pair[1]) ... except ValueError as error: ... print(error) tissot() was given no centres to draw; pass lons= and lats=, or neither for the world grid tissot() was given no centres to draw; pass lons= and lats=, or neither for the world grid tissot() was given no centres to draw; pass lons= and lats=, or neither for the world grid - Two centre lists of different lengths are refused by this method too, with both counts named, rather than by cleopatra from inside the drawer:
nis refused here andradius_mby cleopatra from inside the drawer, so the two messages read differently — but neither leaves a layer behind:>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth import Map >>> with Map(crs=4326) as m: ... for kwargs in ({"n": 3}, {"radius_m": -1.0}): ... try: ... m.tissot(lons=[0.0], lats=[0.0], **kwargs) ... except ValueError as error: ... print(error) ... m.layer_ids tissot() needs n= as a whole number >= 4, the fewest that describe a ring; got 3 radius_m must be a positive, sub-antipodal ground radius in metres (0, 20015114); got -1.0. []
See Also
nightshade: the other overlay cleopatra's solar module draws.
Source code in src/digitalearth/static/builders/decoration.py
3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 | |
colorbar(layer_id=None, *, label=None, visible=True, **kwargs)
#
Show the continuous colour key of a layer.
The Core contract's name for a colour key (#299, #261), and the Core's shape for it — the same call
keys a map on any tier. It was colorbar(layer=-1) here until order 24: keyed by position into
:attr:layers, so a coastline or a text label added after a raster took the key over, and drawn when
called rather than recorded, so a removed layer left its bar behind and a figure written down carried
no note that a key had been asked for. The guide is now recorded on the layer's own colour encoding
and the bar is drawn from that record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str | None
|
Which layer's key to show. |
None
|
label
|
str | None
|
What the bar is called. |
None
|
visible
|
bool
|
|
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so figure decoration reads as one expression. The Core declares |
Self
|
for this name and the web and interactive tiers already answer that way; returning the |
Self
|
|
Self
|
one. What the bar is comes back off the layer instead, and off the description rather than |
Self
|
off the engine: |
Self
|
|
Self
|
written out and read back. The matplotlib |
Self
|
public surface. |
Raises:
| Type | Description |
|---|---|
KeyError
|
when |
ValueError
|
when that layer is coloured by nothing, when no layer on the figure is, or when the
layer is coloured by category — a categorical fill's norm bins the class codes cleopatra
assigned, so a bar over them reads |
Note
This tier draws as many bars as there are guided layers. matplotlib takes any number of
colorbars — which is why :meth:colorbars exists — so three keyed layers are three bars, each
stealing width from the axes. The web tier shows exactly one key and a second replaces the first,
so a figure ported between the two changes its count; asking for one bar here means keying one
layer. Asking twice for the same layer replaces its bar rather than stacking a second.
Examples:
- Key a field and read the recorded guide back off the layer; the bar is an axes of its own
on the figure, and asking twice replaces it rather than stacking a second:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth import Map >>> depth = Dataset.from_array( ... arr=np.array([[1.0, 2.0], [3.0, 4.0]]), ... geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326), ... no_data_value=-9999.0, ... ) >>> m = Map(crs=4326) >>> _ = m.field(depth, name="depth").colorbar(label="m") >>> m.get_layer("depth").symbology.guide() Guide(show=True, title='m', anchor=None) >>> len(m.fig.axes) 2 >>> _ = m.colorbar(label="m") >>> len(m.fig.axes) 2 >>> m.close() - A categorical fill is refused by name, because a bar over it would read the class codes
cleopatra assigned rather than the categories:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from digitalearth import Map >>> cells = gpd.GeoDataFrame( ... {"use": ["arable", "forest", "urban"]}, ... geometry=[Polygon([(i, 0), (i + 1, 0), (i + 1, 1), (i, 1)]) for i in range(3)], ... crs="EPSG:4326", ... ) >>> m = Map(crs=4326) >>> _ = m.choropleth(cells, column="use", scheme="categorical", name="use") >>> m.colorbar("use") # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: layer 'use' is coloured by category, so a colorbar over it would read the ... >>> m.close()
Source code in src/digitalearth/static/core/scene.py
2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 | |
legend(layer_id=None, *, title=None, labels=None, visible=True, **kwargs)
#
Show the keyed colour list of a layer, as one labelled swatch per class.
The Core contract's name for a keyed colour list, in the Core's shape. It took the content
itself here until order 24 — legend(colors, labels) — so a caller had to read the drawn swatches
off layer.category_legend and hand them back, and the key agreed with the picture only while they
did it right. The rows are now derived from the very
:class:~digitalearth.base.spec.scale.Scale the layer publishes, through
:meth:~digitalearth.base.spec.legend.LegendSpec.from_scale, so a swatch equals the colour that was
drawn by construction (#185).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str | None
|
Which layer's classes to describe. |
None
|
title
|
str | None
|
The heading above the swatches. |
None
|
labels
|
Sequence[str] | None
|
Explicit row labels, replacing the derived ones — for units, or for renaming categories.
One per row. |
None
|
visible
|
bool
|
|
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable) — the Core declares |
Self
|
called and whether it is shown read back off the layer's own description, as |
Self
|
|
Self
|
this tier's public surface. |
Raises:
| Type | Description |
|---|---|
KeyError
|
when |
ValueError
|
when that layer is coloured by nothing, when no layer on the figure is, when the
layer publishes no scale for rows to be derived from, or when |
Note
One legend per axes. matplotlib holds a single legend on an axes, so keying a second layer
this way replaces the first layer's swatches rather than adding a box beside them — unlike
:meth:colorbar, where each layer gets its own strip. The displaced layer's guide is switched
off with it, so the figure never describes two swatch keys of which only one can be drawn;
legend() on that layer again brings its key back and takes this one off in its turn (review
M4) — with a re-derived title and derived rows, because a call that passes no title and no
labels derives both, so bringing a displaced key back as it was means repeating them
(review L2). What the record keeps while the key is off is what the figure says it was called;
it is not fed back into the next call. A categorical fill already draws its own
swatch legend through cleopatra; asking here records it on the layer, which is what lets it be
titled, relabelled, hidden and removed with the layer.
Examples:
- Key a categorical fill, then key a second one: the axes holds one legend, the displaced
layer's guide is switched off while keeping the title and rows it was given, and taking
the key back re-derives both:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from digitalearth import Map >>> cells = gpd.GeoDataFrame( ... {"use": ["arable", "forest", "urban"]}, ... geometry=[Polygon([(i, 0), (i + 1, 0), (i + 1, 1), (i, 1)]) for i in range(3)], ... crs="EPSG:4326", ... ) >>> m = Map(crs=4326) >>> for name in ("use", "soil"): ... _ = m.choropleth(cells, column="use", scheme="categorical", name=name) >>> _ = m.legend("use", title="Land use", labels=["Arable", "Forest", "Urban"]) >>> m.get_layer("use").symbology.guide() Guide(show=True, title='Land use', anchor=None) >>> _ = m.legend("soil", title="Soil") >>> m.get_layer("use").symbology.guide() Guide(show=False, title='Land use', anchor=None) >>> _ = m.legend("use") >>> m.get_layer("use").symbology.guide() Guide(show=True, title=None, anchor=None) >>> m.close() - Row labels that do not number the rows are refused by name, whatever
visiblesays:>>> import matplotlib >>> matplotlib.use("Agg") >>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from digitalearth import Map >>> cells = gpd.GeoDataFrame( ... {"use": ["arable", "forest", "urban"]}, ... geometry=[Polygon([(i, 0), (i + 1, 0), (i + 1, 1), (i, 1)]) for i in range(3)], ... crs="EPSG:4326", ... ) >>> m = Map(crs=4326) >>> _ = m.choropleth(cells, column="use", scheme="categorical", name="use") >>> m.legend("use", labels=["only one"]) Traceback (most recent call last): ... ValueError: the key of layer 'use' has 3 rows, so labels= needs 3 labels; got 1 >>> m.close()
Source code in src/digitalearth/static/core/scene.py
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 | |
move_layer(layer_id, index)
#
Move a layer in draw order, by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to move. |
required |
index
|
int
|
Its position afterwards, counted as a list index is — |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
IndexError
|
if the position is outside the figure, or outside the layer's band. |
Note
This reaches the picture and not only the description. matplotlib paints the artists of one
z-order in the order they were added, so the renderer re-arranges the layers it holds
(:meth:~digitalearth.static.render.renderer.Renderer._repaint) — and because that stops at a z-order
boundary, it also deals the layers' own z-orders back out along the new order
(:func:~digitalearth.static.render.renderer._rank_zorders), which is what moves a point layer under a
raster rather than only saying so. The layers keep the z-orders they held between them, so the
move stays inside their slice of the stack and nothing outside it shifts; a zorder= a caller
gave one of the moved layers is superseded, the move being the later word on where it is painted.
Examples:
- Two labels, reordered by id:
Source code in src/digitalearth/static/core/scene.py
remove_layer(layer_id)
#
Take a layer off the figure, by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to remove. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do — a silent no-op here would look exactly like a layer that refused to go away. |
Note
The id goes back to the pool, so a name removed and asked for again is handed back
unsuffixed: an id is reserved exactly while the layer is on the figure, which is the lifetime
all four tiers share (:func:~digitalearth.base.spec.layer.free_layer_id).
The in-memory data is not forgotten. A figure_spec captured before the removal still names
it, and drawing that figure again needs it; :meth:close is where this scene lets its data go.
Examples:
- A layer added and then removed leaves nothing behind:
Source code in src/digitalearth/static/core/scene.py
replace_layer(layer)
#
Swap a layer's description for another, keeping its id and its place in draw order.
This is how a layer is restyled or re-pointed after it has been drawn: a cleopatra glyph bakes its colormap and its class breaks into the artist it built, so the renderer draws the layer again from the new description rather than setting a property on what is there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerSpec
|
The new description. Its id names the layer it replaces. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
CapabilityError
|
if the replacement names a kind this tier does not draw, naming the kind and the
backend that has no drawer for it. Raised off the declaration, before a description is built
or the axes is touched. It subclasses |
KeyError
|
if no layer has that id, naming the ids that do. |
ValueError
|
if |
Examples:
- A label re-described keeps its id and its place:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from dataclasses import replace >>> from digitalearth.static import Map >>> m = Map() >>> _ = m.text(4.9, 52.4, "Amsterdam", name="ams") >>> held = m.get_layer("ams") >>> _ = m.replace_layer(replace(held, label="Capital")) >>> m.get_layer("ams").label 'Capital' >>> m.close()
Source code in src/digitalearth/static/core/scene.py
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 | |
set_visible(layer_id, visible=True)
#
Show or hide a layer, by id.
The layer stays on the figure and in its description — which is what lets it be switched back on, and what tells a saved figure that the layer is there but not drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to toggle. |
required |
visible
|
bool
|
Whether it is drawn. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Examples:
- A hidden layer is still described, and comes back on:
>>> import matplotlib >>> matplotlib.use("Agg") >>> from digitalearth.static import Map >>> m = Map() >>> _ = m.text(4.9, 52.4, "Amsterdam", name="ams") >>> m.set_visible("ams", False).figure_spec.layers.is_visible("ams") False >>> m._renderer.is_visible("ams") False >>> m.set_visible("ams")._renderer.is_visible("ams") True >>> m.close()
Source code in src/digitalearth/static/core/scene.py
animate(stack, *, kind='imshow', fps=DEFAULT_FPS, titles=None, ocean=False, coastlines=False, colorbar=False, cbar_label=None, update='auto', blit=False, **kwargs)
#
Animate a stack of rasters over this map, returning a matplotlib :class:FuncAnimation.
Each frame reprojects stack[i] to the display CRS (pyramids), renders it with the kind method
(cleopatra), optionally draws the ocean disc / coastlines, and — on a globe — applies the projection
frame, so every frame gets the boundary, graticule, and limb-clipping for free. The returned
animation is lazy: call anim.save("out.gif", writer=PillowWriter(fps=...)) or display it.
All frames share one colour treatment, so nothing flickers between them. A scalar field takes
vmin/vmax from kwargs if given, else measured once over the stack. A composite
("rgb_composite" / "hsv_composite") instead takes one per-channel contrast stretch, frozen
once over the stack — without which every frame would re-derive its own 2-98 percentile and the
clip would pump. Pass your own limits=[(lo, hi), ...] to override that scan.
A stated center= belongs to that one treatment too. The diverging ramp it asks for is resolved
once, over the shared scale, rather than by each frame against its own values: a stack that
straddles the centre diverges for the whole clip, and one that does not keeps the sequential ramp
and says so once. Deciding it per frame made the ramp flicker between the two along a clip — and
made the picture depend on update=, since an artist kept across frames froze the first frame's
answer while a redrawn one re-asked it.
Either scan measures frames as they will be drawn, reprojected into the display CRS, so the animation lands on the same scale as the equivalent still. On a globe that means the scale spans what the globe shows: an extreme value on the hidden hemisphere does not set the top of it.
Only what changes is redrawn (ST-9). The first frame draws the whole scene; every frame after it
gives the artist that frame drew the new frame's values (AxesImage.set_data /
QuadMesh.set_array) and touches nothing else, so the ocean disc, the coastlines, the projection
frame, the colorbar and the view survive instead of being thrown away and rebuilt per frame. That is
a strategy, not a different picture: the frames are pixel-identical to the cleared-and-redrawn ones,
which tests/static/test_animate_in_place.py compares buffer by buffer. update= chooses the
path, and a kind or an option that cannot be updated this way (a contour set, a composite, a
per-frame scheme=) is named rather than animated wrongly. A frame the display CRS cannot show
hides the artist for that frame, so an off-limb frame still draws nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
Any
|
An ordered collection of pyramids |
required |
kind
|
str
|
The method used to draw each frame — a scalar field ( |
'imshow'
|
fps
|
float
|
Frames per second (sets the inter-frame interval). Defaults to :data: |
DEFAULT_FPS
|
titles
|
Sequence[str] | None
|
Optional per-frame captions; must match the stack length when given. They are drawn
on the axes and left out of the figure's description, so a heading
:meth: |
None
|
ocean
|
bool
|
When True, fill the ocean disc behind each frame (globe maps only). |
False
|
coastlines
|
bool
|
When True, overlay coastlines each frame (best-effort; ignored if unreachable). |
False
|
colorbar
|
bool
|
When True, add one static colorbar (drawn once, not per frame) using the shared
colour scale. Not available on a composite |
False
|
cbar_label
|
str | None
|
Optional label for the colorbar. |
None
|
update
|
str
|
How the frames after the first are drawn — one of :attr: |
'auto'
|
blit
|
bool
|
When True, build the animation with matplotlib's blitting, which repaints only the artist
each frame returns. It requires the in-place path and is refused without it, and it is
refused alongside |
False
|
**kwargs
|
Any
|
Forwarded to the |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FuncAnimation
|
class: |
FuncAnimation
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Note
blit=True repaints only what the frame function returns, which is the data artist and
nothing else. A per-frame title is therefore refused: matplotlib blits the axes bounding box
and the title is drawn above it, so it would hold the first frame's text. A colorbar is fine —
an animation's colorbar is static by construction, drawn once on its own axes.
Examples:
- Animate a two-frame scalar stack; the animation is lazy, so no frame is drawn yet:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> geo = GeoReference(geo=(-180.0, 3.0, 0.0, 90.0, 0.0, -3.0), epsg=4326) >>> stack = [Dataset.from_array(arr=np.full((60, 120), value, "float32"), geo_ref=geo) ... for value in (1.0, 2.0)] >>> m = Map(crs=4326) >>> anim = m.animate(stack, fps=2) >>> len(list(anim.new_frame_seq())) 2 >>> m.close() - A true-colour stack animates as a composite, on one stretch frozen over the whole stack:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> geo = GeoReference(geo=(-180.0, 3.0, 0.0, 90.0, 0.0, -3.0), epsg=4326) >>> stack = [Dataset.from_array(arr=np.stack([np.full((60, 120), value, "float32")] * 3), ... geo_ref=geo) for value in (1.0, 2.0)] >>> m = Map(crs=4326) >>> anim = m.animate(stack, kind="rgb_composite", fps=2) >>> len(list(anim.new_frame_seq())) 2 >>> m.close() - A composite has no scalar mappable, so asking for a colorbar is refused rather than
answered with a meaningless bar:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> geo = GeoReference(geo=(-180.0, 3.0, 0.0, 90.0, 0.0, -3.0), epsg=4326) >>> stack = [Dataset.from_array(arr=np.stack([np.full((60, 120), 1.0, "float32")] * 3), ... geo_ref=geo)] >>> refused = Map(crs=4326) >>> refused.animate(stack, kind="rgb_composite", colorbar=True) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: colorbar=True is not supported for a 'rgb_composite' animation: ... >>> refused.close() - A field animation can be blitted, because its frames update one image:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> geo = GeoReference(geo=(-180.0, 3.0, 0.0, 90.0, 0.0, -3.0), epsg=4326) >>> fields = [Dataset.from_array(arr=np.full((60, 120), v, "float32"), geo_ref=geo) ... for v in (1.0, 2.0)] >>> scene = Map(crs=4326) >>> len(list(scene.animate(fields, fps=2, blit=True).new_frame_seq())) 2 >>> scene.close() - A contour animation cuts its lines from each frame, so blitting it is refused by name:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import Map >>> geo = GeoReference(geo=(-180.0, 3.0, 0.0, 90.0, 0.0, -3.0), epsg=4326) >>> stack = [Dataset.from_array(arr=np.full((60, 120), v, "float32"), geo_ref=geo) ... for v in (1.0, 2.0)] >>> refused = Map(crs=4326) >>> refused.animate(stack, kind="contourf", blit=True) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: blit=True needs frames that update one artist in place, ... >>> refused.close()
See Also
rotate: Spin one field on an orthographic globe instead of stepping through a stack. save_animation: Write the returned animation to an mp4/GIF.
Source code in src/digitalearth/static/builders/animation.py
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 | |
save(path, **kwargs)
#
Apply the projection frame (for a globe map) then save the figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, PathLike[str]]
|
Destination file path; the extension picks the format matplotlib writes. |
required |
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Path
|
The path that was written, as a :class: |
Source code in src/digitalearth/static/builders/projection.py
close()
#
Close the figure and let go of the in-memory data this scene registered.
Two things are released, because a scene holds two kinds of memory. The figure is matplotlib's,
and a long run of scenes that never closes one keeps every axes alive. The object table is this
package's: it is process-global and holds strong references, so a session that builds maps keeps
every dataset they drew until something says otherwise. This is the caller saying so, and it is what
with calls on the way out.
Closing twice is harmless, and a scene that drew nothing has nothing to forget.
An object: source in a :attr:figure_spec captured from this scene cannot be opened afterwards
— which is what "closed" means for a figure whose data lived only in this process. Save the data and
reference it by path to keep such a figure readable.
The figure is closed only when this scene created it. A figure the scene made itself (a
bare Map()/Scene(), and so every :meth:from_figure round trip) is closed here; a figure
handed in through ax=/fig= is spared, because it belongs to whoever laid it out. This is
371, resolved: a borrowed figure is spared (R2-L12), which brings this into line with#
:meth:~digitalearth.static.globe.textured_globe.TexturedGlobe.close, always gated the same way. The
object table and the pick handler are released on every close regardless — see below.
.. warning::
When the scene owns the figure, this closes the entire self.fig. The panels returned by
:func:~digitalearth.static.panels.figure.grid share one figure none of them owns (each is built
with ax=/fig=), so closing a single panel no longer closes its siblings — and an
:meth:~digitalearth.static.builders.inset.InsetMixin.inset locator, drawn on the host's own
figure, likewise spares the host when closed. Close the scene that made the figure (or call
:meth:save and close it yourself) to take the whole figure down. The pick handler this scene
connected comes off on close whether the figure is owned or borrowed, so a closed borrowed-axes
scene stops answering clicks even though its figure lives on.
Examples:
- A scene that drew nothing closes quietly:
See Also
exit: calls this on the way out of a with block.
Source code in src/digitalearth/static/core/scene.py
2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 | |