Geographic basemap methods (glyphs)#
The glyphs that plot geographic data — ArrayGlyph, MeshGlyph, VectorGlyph,
FlowGlyph, PolygonGlyph, and ScatterGlyph — inherit
cleopatra.geo.GeoMixin, which adds a settable crs property plus five
convenience methods that drop a basemap onto the glyph's own axes without
importing the standalone helpers:
crs— a validated coordinate-reference-system property (int EPSG code, CRS string, orNone); it defaults thecrs=ofadd_tiles/add_featureswhen you omit it, and is validated on assignment.add_tiles→cleopatra.tiles.add_tilesadd_features→cleopatra.reference.add_featuresadd_relief→cleopatra.reference.add_reliefadd_reference_map— a one-call ECMWF/CAMS-style reference-map preset ("ecmwf","ecmwf-dark", or"auto"): grey coastlines + borders, a dashed lon/lat graticule, °W/°N labels, and a subtle frame.add_labels→cleopatra.geo.add_point_labels(dot + text markers for named points, e.g. cities).
Each basemap method is a thin wrapper: it draws on self.ax (the axes produced
when you plot the glyph) and forwards its arguments to the matching standalone
function, which remains the single source of truth. Chart and statistical glyphs
(LineGlyph, StatisticalGlyph, KDEGlyph) deliberately do not inherit
these geo-only methods.
The module also exposes the standalone add_point_labels and available_map_styles
functions and the REFERENCE_MAP_STYLES preset dict (copy or read it to build a
custom preset).
Usage#
import matplotlib
matplotlib.use("Agg") # any backend
import numpy as np
from cleopatra.scatter_glyph import ScatterGlyph
# A few cities as (lon, lat) points.
lon = np.array([-74.0, -0.1, 2.35, 13.4, 37.6, 139.7, 151.2])
lat = np.array([40.7, 51.5, 48.9, 52.5, 55.8, 35.7, -33.9])
glyph = ScatterGlyph(lon, lat, values=np.arange(len(lon)))
glyph.plot() # plot your data first
glyph.add_features("coastline", "110m", colors="0.3") # basemap, on glyph.ax
glyph.add_features("borders", "110m", colors="0.6")
glyph.ax.set_aspect("equal") # 1° lon == 1° lat

The standalone functions still work for plain matplotlib axes or non-geographic glyphs:
import matplotlib.pyplot as plt
from cleopatra.reference import add_features
fig, ax = plt.subplots() # any matplotlib Axes
ax.set_xlim(-180, 180)
ax.set_ylim(-90, 90)
ax.set_aspect("equal")
add_features(ax, "coastline", "110m")
Note
Call these after plotting (so the glyph has an axes), or pass an explicit
ax=. add_relief and crs= reprojection require the cleopatra[tiles]
extra; drawing vector layers in EPSG:4326 needs only numpy + matplotlib.
Module Documentation#
cleopatra.geo
#
Geographic basemap convenience methods for glyphs.
GeoMixin adds three convenience methods -- add_tiles, add_features,
and add_relief -- to the glyph classes that plot geographic data, so a
basemap can be dropped under a plot without importing the standalone
helpers and without repeating the axes:
>>> glyph.plot() # doctest: +SKIP
>>> glyph.add_relief("low") # doctest: +SKIP
>>> glyph.add_features("coastline", "50m") # doctest: +SKIP
Each method is a thin wrapper that draws on the glyph's own axes
(self.ax) and delegates to the single implementation in
cleopatra.tiles / cleopatra.reference. The standalone functions remain
the source of truth; this mixin only removes the import + explicit-axes
boilerplate for the geographic glyphs (ArrayGlyph, MeshGlyph,
VectorGlyph, FlowGlyph, PolygonGlyph, ScatterGlyph). Non-geographic
glyphs (line/bar charts, statistical plots) deliberately do not inherit
it.
Importing this module (and the cleopatra.tiles / cleopatra.reference
modules it calls) does not require the optional cleopatra[tiles] extra:
those modules gate their [tiles] dependencies (mercantile, pyproj,
Pillow, ...) behind their own internal lazy imports, so the extra is
only needed when a basemap is actually drawn.
GeoMixin
#
Mixin giving geographic glyphs add_tiles / add_features / add_relief.
The host class is expected to expose the plotted axes as self.ax
(every cleopatra.glyph.Glyph subclass does). Call these after
plotting, or pass ax= explicitly.
Set self.crs to the CRS of the data plotted on the axes (an EPSG code
or CRS string) and add_features / add_tiles default their crs=
argument to it, so the reference layer is placed in matching
coordinates without restating it on every call. An explicit crs=
still wins; leaving self.crs as None preserves each helper's own
default. add_relief ignores crs -- relief is a fixed EPSG:4326
raster placed by extent.
Source code in src/cleopatra/geo.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
crs
property
writable
#
CRS of the data plotted on self.ax (EPSG code or CRS string).
When set, add_features / add_tiles default crs= to it; None
keeps each helper's own default. The value is validated on
assignment (see cleopatra.geo._validate_crs) so mistakes surface
at glyph.crs = ... rather than later, when a basemap is drawn.
Raises:
| Type | Description |
|---|---|
TypeError
|
If assigned something other than an int, str, or
|
ValueError
|
If assigned a non-positive EPSG code, an empty
string, or (when |
add_features(*args, ax=None, **kwargs)
#
Draw a Natural Earth reference layer on the glyph's axes.
Thin wrapper over cleopatra.reference.add_features; arguments are
forwarded unchanged (e.g. layer, resolution, crs, and style
keywords). When crs is omitted it defaults to self.crs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for
|
()
|
ax
|
Any
|
Axes to draw on. Defaults to the glyph's |
None
|
**kwargs
|
Any
|
Keyword arguments for
|
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The axes, for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the glyph has no axes yet and |
See Also
cleopatra.reference.add_features: The underlying implementation and its full parameter list.
Source code in src/cleopatra/geo.py
add_labels(points, *, ax=None, **kwargs)
#
Annotate named points on the glyph's axes with a dot + label.
Thin wrapper over cleopatra.geo.add_point_labels; draws a plain
dot marker and text label per point, matching the minimalist
city-label look ECMWF/CAMS maps use. Points are plotted at whatever
coordinates the axes is already using -- plain lon/lat for a flat
map, or reprojected x/y for an orthographic globe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
dict[str, tuple[float, float]]
|
Mapping of label text to |
required |
ax
|
Any
|
Axes to draw on. Defaults to the glyph's |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The axes, for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the glyph has no axes yet and |
Examples:
- Label a city on a plotted glyph:
See Also
cleopatra.geo.add_point_labels: The underlying implementation. add_reference_map: The full basemap-chrome preset this pairs with.
Source code in src/cleopatra/geo.py
add_reference_map(style='ecmwf', *, ax=None, extent=None, resolution=None, graticule_step=None, zorder=5)
#
Dress the glyph's axes in a weather-centre reference-map style.
One call composes the recipe that otherwise takes ~15 lines of
matplotlib after plot/animate: grey Natural Earth coastline
+ borders, a dashed lon/lat graticule, °W/°N degree labels,
and a subtle frame. It layers on top of the existing data, so call
it after plotting.
The map is drawn in the axes' current geographic coordinates. Pass
extent (or construct the glyph with extent=) so the axes are
georeferenced — otherwise the coastlines cannot align with the data
and a warning is emitted. Deriving that extent from a source dataset
is the caller's job (cleopatra renders supplied coordinates; it does
not read geotransforms).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str
|
A name from |
'ecmwf'
|
ax
|
Any
|
Axes to draw on. Defaults to the glyph's |
None
|
extent
|
Any
|
Optional |
None
|
resolution
|
str | None
|
Natural Earth resolution for the coastline/borders
( |
None
|
graticule_step
|
float | None
|
Degree spacing for the graticule. Defaults to a "nice" step giving ~6 divisions across the wider span. |
None
|
zorder
|
int
|
Draw order for the reference layers (drawn above the data; the graticule sits just below the coastlines). |
5
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The decorated axes, for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the glyph has no axes yet and |
ValueError
|
If |
Examples:
- Dress a georeferenced field in the ECMWF look:
See Also
add_features: The Natural Earth layer helper this composes. available_map_styles: The built-in preset names.
Source code in src/cleopatra/geo.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
add_relief(*args, ax=None, **kwargs)
#
Draw a hypsometric relief backdrop under the glyph's data.
Thin wrapper over cleopatra.reference.add_relief; arguments are
forwarded unchanged (e.g. resolution, extent, alpha).
Requires the cleopatra[tiles] extra (Pillow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for
|
()
|
ax
|
Any
|
Axes to draw on. Defaults to the glyph's |
None
|
**kwargs
|
Any
|
Keyword arguments for
|
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The axes, for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the glyph has no axes yet and |
See Also
cleopatra.reference.add_relief: The underlying implementation and its full parameter list.
Source code in src/cleopatra/geo.py
add_tiles(*args, ax=None, **kwargs)
#
Overlay a web-tile basemap on the glyph's axes.
Thin wrapper over cleopatra.tiles.add_tiles; positional and
keyword arguments are forwarded unchanged (e.g. source, crs,
zoom, alpha). When crs is omitted it defaults to self.crs.
Requires the cleopatra[tiles] extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for |
()
|
ax
|
Any
|
Axes to draw on. Defaults to the glyph's |
None
|
**kwargs
|
Any
|
Keyword arguments for |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The axes, for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the glyph has no axes yet and |
See Also
cleopatra.tiles.add_tiles: The underlying implementation and its full parameter list.
Source code in src/cleopatra/geo.py
add_point_labels(ax, points, *, color='white', marker_size=5.0, fontsize=9.0, offset=(4.0, 0.0), zorder=6)
#
Annotate named points with a plain dot marker + text label.
Draws a small circular marker at each point and a plain text label
beside it -- no halo, no bounding box -- matching the minimalist look
ECMWF/CAMS maps use for city labels. points are plotted at whatever
coordinates ax is already using (plain lon/lat on a flat axes, or
projected x/y on an orthographic globe -- reproject the points yourself,
e.g. with the same transformer cleopatra.projection.orthographic_grid
builds, before calling this on a globe view), so this composes with any
projection or colour styling; it makes no assumption about either.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Any
|
Axes to draw on. |
required |
points
|
dict[str, tuple[float, float]]
|
Mapping of label text to |
required |
color
|
str
|
Colour for both the marker and the label text. |
'white'
|
marker_size
|
float
|
Marker size in points. |
5.0
|
fontsize
|
float
|
Label font size in points. |
9.0
|
offset
|
tuple[float, float]
|
|
(4.0, 0.0)
|
zorder
|
int
|
Draw order for both the marker and the label. |
6
|
Returns:
| Name | Type | Description |
|---|---|---|
Axes |
Any
|
The same |
Examples:
- Label two points and read back the drawn markers/labels:
>>> import matplotlib.pyplot as plt >>> from cleopatra.geo import add_point_labels >>> fig, ax = plt.subplots() >>> _ = add_point_labels(ax, {"London": (-0.1, 51.5), "Moscow": (37.6, 55.8)}) >>> len(ax.lines) # one marker per point 2 >>> [t.get_text() for t in ax.texts] ['London', 'Moscow'] >>> plt.close(fig) - An empty mapping draws nothing but still returns
ax, for chaining:
See Also
GeoMixin.add_labels: The glyph convenience wrapper for this function.
Source code in src/cleopatra/geo.py
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 | |
available_map_styles()
#
Return the built-in add_reference_map style names.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The preset names accepted by |
list[str]
|
|
Examples:
>>> from cleopatra.geo import available_map_styles
>>> available_map_styles()
['ecmwf', 'ecmwf-dark']