Heatmap Layer Example¶
This notebook demonstrates the DeckGL HeatmapLayer for density visualization.
In [ ]:
Copied!
# %pip install anymap-ts
# %pip install anymap-ts
Basic Heatmap Layer¶
In [ ]:
Copied!
import random
from anymap_ts import DeckGLMap
# Generate random points around San Francisco
points = [
{
"coordinates": [
-122.4 + random.uniform(-0.3, 0.3),
37.8 + random.uniform(-0.3, 0.3),
]
}
for _ in range(2000)
]
m = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m.add_basemap("CartoDB.DarkMatter")
m.add_heatmap_layer(
data=points,
name="heatmap-basic",
get_position="coordinates",
radius_pixels=50,
intensity=1,
threshold=0.05,
opacity=1,
)
m
import random
from anymap_ts import DeckGLMap
# Generate random points around San Francisco
points = [
{
"coordinates": [
-122.4 + random.uniform(-0.3, 0.3),
37.8 + random.uniform(-0.3, 0.3),
]
}
for _ in range(2000)
]
m = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m.add_basemap("CartoDB.DarkMatter")
m.add_heatmap_layer(
data=points,
name="heatmap-basic",
get_position="coordinates",
radius_pixels=50,
intensity=1,
threshold=0.05,
opacity=1,
)
m
Heatmap with Custom Color Range¶
In [ ]:
Copied!
custom_colors = [
[255, 255, 178, 25],
[254, 217, 118, 85],
[254, 178, 76, 127],
[253, 141, 60, 170],
[240, 59, 32, 212],
[189, 0, 38, 255],
]
m2 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m2.add_basemap("CartoDB.DarkMatter")
m2.add_heatmap_layer(
data=points,
name="heatmap-custom",
get_position="coordinates",
radius_pixels=40,
intensity=1.2,
color_range=custom_colors,
)
m2
custom_colors = [
[255, 255, 178, 25],
[254, 217, 118, 85],
[254, 178, 76, 127],
[253, 141, 60, 170],
[240, 59, 32, 212],
[189, 0, 38, 255],
]
m2 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m2.add_basemap("CartoDB.DarkMatter")
m2.add_heatmap_layer(
data=points,
name="heatmap-custom",
get_position="coordinates",
radius_pixels=40,
intensity=1.2,
color_range=custom_colors,
)
m2
Heatmap with Weighted Points¶
In [ ]:
Copied!
# Points with weight values
weighted_points = [
{
"coordinates": [
-122.4 + random.uniform(-0.3, 0.3),
37.8 + random.uniform(-0.3, 0.3),
],
"weight": random.random(),
}
for _ in range(2000)
]
m3 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m3.add_basemap("CartoDB.DarkMatter")
m3.add_heatmap_layer(
data=weighted_points,
name="heatmap-weighted",
get_position="coordinates",
get_weight="weight",
radius_pixels=35,
intensity=1,
)
m3
# Points with weight values
weighted_points = [
{
"coordinates": [
-122.4 + random.uniform(-0.3, 0.3),
37.8 + random.uniform(-0.3, 0.3),
],
"weight": random.random(),
}
for _ in range(2000)
]
m3 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m3.add_basemap("CartoDB.DarkMatter")
m3.add_heatmap_layer(
data=weighted_points,
name="heatmap-weighted",
get_position="coordinates",
get_weight="weight",
radius_pixels=35,
intensity=1,
)
m3
Heatmap with Layer Control¶
In [ ]:
Copied!
m4 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m4.add_basemap("CartoDB.DarkMatter")
m4.add_heatmap_layer(
data=points,
name="heatmap-density",
get_position="coordinates",
radius_pixels=50,
)
m4.add_layer_control()
m4
m4 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m4.add_basemap("CartoDB.DarkMatter")
m4.add_heatmap_layer(
data=points,
name="heatmap-density",
get_position="coordinates",
radius_pixels=50,
)
m4.add_layer_control()
m4
Using the Generic add_deckgl_layer Method¶
In [ ]:
Copied!
m5 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m5.add_basemap("CartoDB.DarkMatter")
m5.add_deckgl_layer(
layer_type="HeatmapLayer",
data=points,
name="heatmap-generic",
getPosition="coordinates",
radiusPixels=45,
intensity=1,
threshold=0.05,
)
m5
m5 = DeckGLMap(center=[-122.4, 37.8], zoom=11)
m5.add_basemap("CartoDB.DarkMatter")
m5.add_deckgl_layer(
layer_type="HeatmapLayer",
data=points,
name="heatmap-generic",
getPosition="coordinates",
radiusPixels=45,
intensity=1,
threshold=0.05,
)
m5
Export to HTML¶
In [ ]:
Copied!
m.to_html("heatmap_layer_example.html")
m.to_html("heatmap_layer_example.html")