Skip to content

23 colormaps

image image image

Creating colormaps with a single line of code

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap

This notebook requires the ipyleaflet plotting backend. Folium is not supported.

1
2
from leafmap import leafmap
import leafmap.colormaps as cm

Color palette for DEM data.

1
cm.palettes.dem

Show the DEM palette.

1
cm.plot_colormap(colors=cm.palettes.dem, axis_off=True)

Color palette for NDVI data.

1
cm.palettes.ndvi

Show the NDVI palette.

1
cm.plot_colormap(colors=cm.palettes.ndvi)

Specify the number of classes for a palette.

1
cm.get_palette("terrain", n_class=8)

Show the terrain palette with 8 classes.

1
cm.plot_colormap(colors=cm.get_palette("terrain", n_class=8))

Create a palette with custom colors, label, and font size.

1
cm.plot_colormap(colors=["red", "green", "blue"], label="Temperature", font_size=12)

Create a discrete color palette.

1
2
3
cm.plot_colormap(
    colors=["red", "green", "blue"], discrete=True, label="Temperature", font_size=12
)

Specify the width and height for the palette.

1
2
3
4
5
6
7
8
9
cm.plot_colormap(
    "terrain",
    label="Elevation",
    width=8.0,
    height=0.4,
    orientation="horizontal",
    vmin=0,
    vmax=1000,
)

Change the orentation of the colormap to be vertical.

1
2
3
4
5
6
7
8
9
cm.plot_colormap(
    "terrain",
    label="Elevation",
    width=0.4,
    height=4,
    orientation="vertical",
    vmin=0,
    vmax=1000,
)

Add a horizontal colorbar to an interactive map.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m.add_colormap(
    "terrain",
    label="Elevation",
    width=8.0,
    height=0.4,
    orientation="horizontal",
    vmin=0,
    vmax=4000,
)
m

Add a vertical colorbar to an interactive map.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m.add_colormap(
    "terrain",
    label="Elevation",
    width=0.4,
    height=4,
    orientation="vertical",
    vmin=0,
    vmax=4000,
)
m

Show all available colormaps.

1
cm.plot_colormaps(width=12, height=0.4)