Creating colormaps with a single line of code
Uncomment the following line to install leafmap if needed.
# !pip install leafmap
This notebook requires the ipyleaflet plotting backend. Folium is not supported.
from leafmap import leafmap
import leafmap.colormaps as cm
Color palette for DEM data.
cm.palettes.dem
Show the DEM palette.
cm.plot_colormap(colors=cm.palettes.dem, axis_off=True)
Color palette for NDVI data.
cm.palettes.ndvi
Show the NDVI palette.
cm.plot_colormap(colors=cm.palettes.ndvi)
Specify the number of classes for a palette.
cm.get_palette("terrain", n_class=8)
Show the terrain palette with 8 classes.
cm.plot_colormap(colors=cm.get_palette("terrain", n_class=8))
Create a palette with custom colors, label, and font size.
cm.plot_colormap(colors=["red", "green", "blue"], label="Temperature", font_size=12)
Create a discrete color palette.
cm.plot_colormap(
colors=["red", "green", "blue"], discrete=True, label="Temperature", font_size=12
)
Specify the width and height for the palette.
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.
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.
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.
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.
cm.plot_colormaps(width=12, height=0.4)