Skip to content

07 colorbar

image image image

Adding custom colorbars to the map

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap

Continuous colorbar

1
import leafmap

Add a WMS layer to the map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Map = leafmap.Map()

url = "https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WMSServer?"
Map.add_wms_layer(
    url,
    layers="3DEPElevation:Hillshade Elevation Tinted",
    name="USGS 3DEP Elevation",
    format="image/png",
    transparent=True,
)

Add a continuous colorbar with a custom palette to the map.

1
2
3
4
5
6
7
colors = ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"]
vmin = 0
vmax = 4000

Map.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)

Map

Categorical colorbar

Add a WMS layer to the map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Map = leafmap.Map()

url = "https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WMSServer?"
Map.add_wms_layer(
    url,
    layers="3DEPElevation:Hillshade Elevation Tinted",
    name="USGS 3DEP Elevation",
    format="image/png",
    transparent=True,
)

Add a categorical colorbar with a custom palette to the map.

1
2
3
4
5
6
colors = ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"]
vmin = 0
vmax = 4000

Map.add_colorbar(colors=colors, vmin=vmin, vmax=vmax, categorical=True, step=4)
Map