CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gmaps

Google maps plugin for Jupyter notebooks with interactive visualization capabilities

Pending
Overview
Eval results
Files

heatmap.mddocs/

Heatmap Visualization

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.

Capabilities

Heatmap Layer Creation

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

def heatmap_layer(locations, weights=None, max_intensity=None, dissipating=True, point_radius=None, opacity=0.6, gradient=None):
    """
    Create a heatmap layer showing point density.

    Parameters:
    - locations (array-like): Array of (latitude, longitude) tuples
    - weights (array-like, optional): Array of weights corresponding to locations
    - max_intensity (float, optional): Maximum intensity value for normalization
    - dissipating (bool): Whether point radius changes with zoom level
    - point_radius (int, optional): Pixel radius for each point
    - opacity (float): Layer opacity between 0.0 and 1.0
    - gradient (list, optional): Custom color gradient specification

    Returns:
    Heatmap or WeightedHeatmap: Heatmap layer instance
    """

Simple Heatmap Widget

Basic heatmap layer showing point density without weights.

class Heatmap:
    """
    Simple heatmap layer widget for unweighted point data.
    
    Attributes:
    - locations (list): Array of (latitude, longitude) points
    - max_intensity (float): Maximum intensity value
    - point_radius (int): Pixel radius for each point
    - dissipating (bool): Whether radius changes with zoom
    - opacity (float): Layer opacity (0.0-1.0)
    - gradient (list): Color gradient specification
    """

Weighted Heatmap Widget

Heatmap layer with weighted points for showing intensity variations.

class WeightedHeatmap:
    """
    Weighted heatmap layer widget for point data with intensity values.
    
    Attributes:
    - locations (list): Array of (latitude, longitude) points
    - weights (list): Array of point weights
    - max_intensity (float): Maximum intensity value
    - point_radius (int): Pixel radius for each point
    - dissipating (bool): Whether radius changes with zoom
    - opacity (float): Layer opacity (0.0-1.0)
    - gradient (list): Color gradient specification
    """

Usage Examples

Basic Heatmap

import gmaps
import gmaps.datasets

gmaps.configure(api_key="YOUR_API_KEY")

# Load earthquake data
earthquake_data = gmaps.datasets.load_dataset_as_df('earthquakes')
locations = earthquake_data[['latitude', 'longitude']]

# Create basic heatmap
fig = gmaps.figure()
heatmap_layer = gmaps.heatmap_layer(locations)
fig.add_layer(heatmap_layer)
fig

Weighted Heatmap

import gmaps
import gmaps.datasets

gmaps.configure(api_key="YOUR_API_KEY")

# Load earthquake data with magnitudes
earthquake_data = gmaps.datasets.load_dataset_as_df('earthquakes')
locations = earthquake_data[['latitude', 'longitude']]
magnitudes = earthquake_data['magnitude']

# Create weighted heatmap
fig = gmaps.figure()
heatmap_layer = gmaps.heatmap_layer(
    locations, 
    weights=magnitudes,
    max_intensity=8.0,
    point_radius=20
)
fig.add_layer(heatmap_layer)
fig

Custom Styled Heatmap

import gmaps

gmaps.configure(api_key="YOUR_API_KEY")

# Sample location data
locations = [
    (37.7749, -122.4194),  # San Francisco
    (37.7849, -122.4094),
    (37.7649, -122.4294),
    (37.7949, -122.3994)
]

# Custom gradient from blue to red
custom_gradient = [
    'rgba(0, 0, 255, 0)',      # Transparent blue
    'rgba(0, 0, 255, 1)',      # Blue
    'rgba(0, 255, 255, 1)',    # Cyan
    'rgba(0, 255, 0, 1)',      # Green
    'rgba(255, 255, 0, 1)',    # Yellow
    'rgba(255, 0, 0, 1)'       # Red
]

# Create custom heatmap
fig = gmaps.figure()
heatmap_layer = gmaps.heatmap_layer(
    locations,
    max_intensity=10,
    point_radius=50,
    dissipating=False,
    opacity=0.8,
    gradient=custom_gradient
)
fig.add_layer(heatmap_layer)
fig

Dynamic Heatmap Updates

import gmaps
import numpy as np

gmaps.configure(api_key="YOUR_API_KEY")

# Generate random data
np.random.seed(42)
num_points = 1000
lat_center, lng_center = 37.7749, -122.4194
locations = np.random.normal(
    [lat_center, lng_center], 
    [0.01, 0.01], 
    (num_points, 2)
)
weights = np.random.exponential(1, num_points)

# Create heatmap
fig = gmaps.figure(center=(lat_center, lng_center), zoom_level=12)
heatmap_layer = gmaps.heatmap_layer(locations, weights=weights)
fig.add_layer(heatmap_layer)

# Update heatmap data dynamically
new_weights = np.random.exponential(2, num_points)
heatmap_layer.weights = new_weights

fig

Install with Tessl CLI

npx tessl i tessl/pypi-gmaps

docs

datasets.md

directions.md

drawing.md

figure-map.md

geojson.md

heatmap.md

index.md

markers.md

transportation.md

tile.json