Skip to content

25 map title

image image image

Creating a population heat map with a colorbar and map title

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap

The notebook requires the folium plotting backend. ipyleaflet is not supported.

1
import leafmap.foliumap as leafmap

Creates an interactive folium map.

1
m = leafmap.Map()

Specify the latitude, longitude, and value columns to create the heat map.

1
in_csv = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.csv"

Specify the file path to the CSV. It can either be a file locally or on the Internet.

1
2
3
4
5
6
7
8
m.add_heatmap(
    in_csv,
    latitude="latitude",
    longitude="longitude",
    value="pop_max",
    name="Heat map",
    radius=20,
)

Adds a colorbar to the map.

1
2
3
4
5
colors = ["blue", "lime", "red"]
vmin = 0
vmax = 10000

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

Adds a title to the map.

1
m.add_title("World Population Heat Map", font_size="20px", align="center")
1
m

Save the map as an HTML.

1
m.to_html("heatmap.html")