or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

datasets.mddirections.mddrawing.mdfigure-map.mdgeojson.mdheatmap.mdindex.mdmarkers.mdtransportation.md

heatmap.mddocs/

0

# Heatmap Visualization

1

2

Create density visualizations showing geographic patterns in point data. Heatmaps are excellent for visualizing the density and intensity of geographic phenomena such as population centers, crime incidents, or natural events.

3

4

## Capabilities

5

6

### Heatmap Layer Creation

7

8

Create heatmap layers from location data with optional weighting and styling customization.

9

10

```python { .api }

11

def heatmap_layer(locations, weights=None, max_intensity=None, dissipating=True, point_radius=None, opacity=0.6, gradient=None):

12

"""

13

Create a heatmap layer showing point density.

14

15

Parameters:

16

- locations (array-like): Array of (latitude, longitude) tuples

17

- weights (array-like, optional): Array of weights corresponding to locations

18

- max_intensity (float, optional): Maximum intensity value for normalization

19

- dissipating (bool): Whether point radius changes with zoom level

20

- point_radius (int, optional): Pixel radius for each point

21

- opacity (float): Layer opacity between 0.0 and 1.0

22

- gradient (list, optional): Custom color gradient specification

23

24

Returns:

25

Heatmap or WeightedHeatmap: Heatmap layer instance

26

"""

27

```

28

29

### Simple Heatmap Widget

30

31

Basic heatmap layer showing point density without weights.

32

33

```python { .api }

34

class Heatmap:

35

"""

36

Simple heatmap layer widget for unweighted point data.

37

38

Attributes:

39

- locations (list): Array of (latitude, longitude) points

40

- max_intensity (float): Maximum intensity value

41

- point_radius (int): Pixel radius for each point

42

- dissipating (bool): Whether radius changes with zoom

43

- opacity (float): Layer opacity (0.0-1.0)

44

- gradient (list): Color gradient specification

45

"""

46

```

47

48

### Weighted Heatmap Widget

49

50

Heatmap layer with weighted points for showing intensity variations.

51

52

```python { .api }

53

class WeightedHeatmap:

54

"""

55

Weighted heatmap layer widget for point data with intensity values.

56

57

Attributes:

58

- locations (list): Array of (latitude, longitude) points

59

- weights (list): Array of point weights

60

- max_intensity (float): Maximum intensity value

61

- point_radius (int): Pixel radius for each point

62

- dissipating (bool): Whether radius changes with zoom

63

- opacity (float): Layer opacity (0.0-1.0)

64

- gradient (list): Color gradient specification

65

"""

66

```

67

68

## Usage Examples

69

70

### Basic Heatmap

71

72

```python

73

import gmaps

74

import gmaps.datasets

75

76

gmaps.configure(api_key="YOUR_API_KEY")

77

78

# Load earthquake data

79

earthquake_data = gmaps.datasets.load_dataset_as_df('earthquakes')

80

locations = earthquake_data[['latitude', 'longitude']]

81

82

# Create basic heatmap

83

fig = gmaps.figure()

84

heatmap_layer = gmaps.heatmap_layer(locations)

85

fig.add_layer(heatmap_layer)

86

fig

87

```

88

89

### Weighted Heatmap

90

91

```python

92

import gmaps

93

import gmaps.datasets

94

95

gmaps.configure(api_key="YOUR_API_KEY")

96

97

# Load earthquake data with magnitudes

98

earthquake_data = gmaps.datasets.load_dataset_as_df('earthquakes')

99

locations = earthquake_data[['latitude', 'longitude']]

100

magnitudes = earthquake_data['magnitude']

101

102

# Create weighted heatmap

103

fig = gmaps.figure()

104

heatmap_layer = gmaps.heatmap_layer(

105

locations,

106

weights=magnitudes,

107

max_intensity=8.0,

108

point_radius=20

109

)

110

fig.add_layer(heatmap_layer)

111

fig

112

```

113

114

### Custom Styled Heatmap

115

116

```python

117

import gmaps

118

119

gmaps.configure(api_key="YOUR_API_KEY")

120

121

# Sample location data

122

locations = [

123

(37.7749, -122.4194), # San Francisco

124

(37.7849, -122.4094),

125

(37.7649, -122.4294),

126

(37.7949, -122.3994)

127

]

128

129

# Custom gradient from blue to red

130

custom_gradient = [

131

'rgba(0, 0, 255, 0)', # Transparent blue

132

'rgba(0, 0, 255, 1)', # Blue

133

'rgba(0, 255, 255, 1)', # Cyan

134

'rgba(0, 255, 0, 1)', # Green

135

'rgba(255, 255, 0, 1)', # Yellow

136

'rgba(255, 0, 0, 1)' # Red

137

]

138

139

# Create custom heatmap

140

fig = gmaps.figure()

141

heatmap_layer = gmaps.heatmap_layer(

142

locations,

143

max_intensity=10,

144

point_radius=50,

145

dissipating=False,

146

opacity=0.8,

147

gradient=custom_gradient

148

)

149

fig.add_layer(heatmap_layer)

150

fig

151

```

152

153

### Dynamic Heatmap Updates

154

155

```python

156

import gmaps

157

import numpy as np

158

159

gmaps.configure(api_key="YOUR_API_KEY")

160

161

# Generate random data

162

np.random.seed(42)

163

num_points = 1000

164

lat_center, lng_center = 37.7749, -122.4194

165

locations = np.random.normal(

166

[lat_center, lng_center],

167

[0.01, 0.01],

168

(num_points, 2)

169

)

170

weights = np.random.exponential(1, num_points)

171

172

# Create heatmap

173

fig = gmaps.figure(center=(lat_center, lng_center), zoom_level=12)

174

heatmap_layer = gmaps.heatmap_layer(locations, weights=weights)

175

fig.add_layer(heatmap_layer)

176

177

# Update heatmap data dynamically

178

new_weights = np.random.exponential(2, num_points)

179

heatmap_layer.weights = new_weights

180

181

fig

182

```