Skip to content

Open in Colab

Basemaps over one another

Draw basemaps over one another: they share one attribution. Mapterhorn.Hillshade is transparent, to shade another basemap (under its labels with labels="above"), and imagery takes the labels of a map on top (labels="only"), or the whole map made translucent with alpha (it goes to imshow, as other extra arguments do).

import geopandas
import matplotlib.pyplot as plt

import basemaplibre as bml
def around(lon, lat, half_width):
    """Axes limits of a square around a point, half_width Web Mercator meters to each side."""
    x, y = geopandas.GeoSeries.from_xy([lon], [lat], crs=4326).to_crs(3857).iloc[0].coords[0]
    return x - half_width, x + half_width, y - half_width, y + half_width
fig, axs = plt.subplots(1, 3, figsize=(9.6, 3.6), layout="constrained")
titles = [
    "Positron over Mapterhorn.Hillshade",
    "EOX imagery with labels",
    "EOX imagery under Positron,\nalpha=0.5",
]
for ax, title in zip(axs, titles, strict=True):
    ax.axis(around(138.73, 35.43, 20000))
    ax.set_aspect("equal")
    ax.set_axis_off()
    ax.set_title(title, fontsize=10)
bml.add_basemap(axs[0], source="OpenFreeMap.Positron", labels="above")
bml.add_basemap(axs[0], source="Mapterhorn.Hillshade")
bml.add_basemap(axs[1], source="EOX.Sentinel2Cloudless")
bml.add_basemap(axs[1], source="OpenFreeMap.Liberty", labels="only")
bml.add_basemap(axs[2], source="EOX.Sentinel2Cloudless")
bml.add_basemap(axs[2], source="OpenFreeMap.Positron", alpha=0.5)

png