Basemap#
Add web-tile basemaps (OpenStreetMap and other XYZ providers) under a plotted raster or vector.
get_provider— resolve a tile provider by name.add_basemap— draw a basemap onto a matplotlib axes.
See the Basemap example for a runnable walkthrough.
Requires the [viz] extra.
pyramids.basemap.get_provider(name=None)
#
Resolve a web-tile provider by name.
Thin wrapper over :func:cleopatra.tiles.get_provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or None
|
Dot-separated provider name (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
xyzservices.TileProvider: The resolved tile provider object (URL template + attribution). |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
If the cleopatra |
ValueError
|
If the provider name cannot be resolved. |
Examples:
- Resolve the default OpenStreetMap provider:
- Resolve a specific provider and inspect its URL:
- Invalid provider name raises
ValueError:
See Also
add_basemap: Uses get_provider internally (via cleopatra) when
source is a string.
cleopatra.tiles.get_provider: The underlying implementation.
Source code in src/pyramids/basemap/basemap.py
pyramids.basemap.add_basemap(ax, crs=3857, source=None, zoom='auto', alpha=1.0, attribution=True, zorder=-1, interpolation='bilinear', timeout=10, retries=2)
#
Add a web-tile basemap underneath the data plotted on ax.
Thin wrapper over :func:cleopatra.tiles.add_tiles: fetches XYZ web
tiles for the axes' geographic extent, stitches them into a single
image, reprojects to the data's CRS via GDAL when crs is not Web
Mercator, and renders the image beneath the data layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes to add the basemap to. Must have data already plotted so that the axis limits define the geographic extent. |
required |
crs
|
int or str
|
CRS of the data on the axes — an EPSG integer (e.g. |
3857
|
source
|
str, TileProvider, or None
|
Tile provider. |
None
|
zoom
|
int or 'auto'
|
Tile zoom level. |
'auto'
|
alpha
|
float
|
Opacity of the basemap ( |
1.0
|
attribution
|
str or bool
|
|
True
|
zorder
|
int
|
Matplotlib zorder. |
-1
|
interpolation
|
str
|
Interpolation method for |
'bilinear'
|
timeout
|
int
|
HTTP request timeout in seconds per tile. Default is |
10
|
retries
|
int
|
Number of retry attempts per failed tile. Default is |
2
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib.axes.Axes: The axes with the basemap added (whatever
:func: |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
If the cleopatra |
TypeError
|
If |
ValueError
|
If the axes have no data extent, the extent is
degenerate, or |
ConnectionError
|
If tiles cannot be fetched from the provider. |
Examples:
- Add a default OpenStreetMap basemap to a Dataset plot
(
+SKIP— needs a real raster, the[viz]extra, and network access to the tile provider): - Use a different tile provider with transparency:
See Also
get_provider: Resolve a tile provider name to a TileProvider.
cleopatra.tiles.add_tiles: The underlying implementation.
Source code in src/pyramids/basemap/basemap.py
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 | |