Menu

Geospatial
Interactive
29 Python scripts generated for connection map this week

Connection Map

Chart overview

Connection maps (also called flow maps or route maps) display relationships and movements between geographic locations using lines or arcs.

Key points

  • They're commonly used to visualize flight routes, trade flows, migration patterns, and communication networks.
  • Great circle paths can be used to show the shortest distance between points on a globe, creating visually appealing curved routes that accurately represent real-world paths.

Interactive Visualization

Loading interactive chart...

This is an interactive connection map. You can zoom, pan, and hover over elements for details.

Create This Chart Now

Generate publication-ready connection maps with AI in seconds. No coding required – just describe your data and let AI do the work.

View example prompt
Example AI Prompt

"Create an interactive connection map showing 'International Flight Routes' from New York (JFK) to 10 major world cities. Generate data including destinations (London, Tokyo, Paris, Dubai, Sydney, São Paulo, Singapore, Hong Kong, Frankfurt, Toronto) with weekly passenger volumes (1,500-3,200 range). Draw great circle arcs colored by passenger volume using a blue-to-red gradient. Size origin marker larger (14px) and destinations by passenger volume. Add hover tooltips showing route, distance in miles, and weekly passengers. Use CartoDB dark basemap for contrast. Include a legend for passenger volume and add a title with total weekly passengers."

How to create this chart in 30 seconds

1

Upload Data

Drag & drop your Excel or CSV file. Plotivy securely processes it in your browser.

2

AI Generation

Our AI analyzes your data and generates the Connection Map code automatically.

3

Customize & Export

Tweak the design with natural language, then export as high-res PNG, SVG or PDF.

Python Code Example

example.py
import plotly.graph_objects as go
import numpy as np
import pandas as pd

# Generate flight route dataset
cities = {
    'New York': (40.7128, -74.0060),
    'London': (51.5074, -0.1278),
    'Paris': (48.8566, 2.3522),
    'Tokyo': (35.6762, 139.6503),
    'Sydney': (-33.8688, 151.2093),
    'Dubai': (25.2048, 55.2708),
    'Singapore': (1.3521, 103.8198),
    'Hong Kong': (22.3193, 114.1694),
    'Los Angeles': (34.0522, -118.2437),
    'San Francisco': (37.7749, -122.4194),
    'Chicago': (41.8781, -87.6298),
    'Miami': (25.7617, -80.1918),
    'Toronto': (43.6532, -79.3832),
    'Berlin': (52.5200, 13.4050),
    'Madrid': (40.4168, -3.7038)
}

# Create flight routes from New York to other cities
routes = []
for city, (lat, lon) in cities.items():
    if city != 'New York':
        routes.append({
            'from': 'New York',
            'to': city,
            'from_lat': cities['New York'][0],
            'from_lon': cities['New York'][1],
            'to_lat': lat,
            'to_lon': lon
        })

# Create figure
fig = go.Figure()

# Add flight routes as lines
for route in routes:
    # Create curved flight path using intermediate points
    t = np.linspace(0, 1, 100)
    
    # Calculate great circle path with some curvature
    lat1, lon1 = np.radians(route['from_lat']), np.radians(route['from_lon'])
    lat2, lon2 = np.radians(route['to_lat']), np.radians(route['to_lon'])
    
    # Interpolate along great circle
    x = np.linspace(0, 1, 100)
    lats = []
    lons = []
    
    for xi in x:
        # Linear interpolation with slight arc
        lat_interp = lat1 + (lat2 - lat1) * xi
        lon_interp = lon1 + (lon2 - lon1) * xi
        
        # Add some curvature to make it look like a flight path
        arc_height = 0.3 * np.sin(np.pi * xi)
        lat_interp += arc_height * (lat2 - lat1) / abs(lat2 - lat1 + 0.001)
        
        lats.append(np.degrees(lat_interp))
        lons.append(np.degrees(lon_interp))
    
    fig.add_trace(go.Scattergeo(
        lat=lats,
        lon=lons,
        mode='lines',
        line=dict(width=1, color='blue'),
        opacity=0.6,
        showlegend=False
    ))

# Add city markers
for city, (lat, lon) in cities.items():
    if city == 'New York':
        color = 'red'
        size = 12
    else:
        color = 'blue'
        size = 8
    
    fig.add_trace(go.Scattergeo(
        lat=[lat],
        lon=[lon],
        mode='markers',
        marker=dict(
            size=size,
            color=color,
            symbol='circle'
        ),
        text=city,
        name=city,
        showlegend=False
    ))

# Update layout
fig.update_layout(
    title='Flight Routes from New York to Major Cities',
    geo=dict(
        scope='world',
        projection_type='natural earth',
        showland=True,
        landcolor='lightgray',
        showocean=True,
        oceancolor='lightblue',
        showcountries=True,
        countrycolor='white'
    ),
    width=1000,
    height=600,
    margin=dict(l=0, r=0, t=50, b=0)
)

# Add annotation for New York
fig.add_annotation(
    x=cities['New York'][1],
    y=cities['New York'][0],
    text='New York (Hub)',
    showarrow=True,
    arrowhead=2,
    arrowsize=1,
    arrowwidth=2,
    arrowcolor='red'
)

# Generate x-values for the specified range (though not used in geographic plot)
x_values = np.linspace(-10.0, 10.0, 100)

# The x_values are generated as requested but not used in this geographic visualization
# since we're plotting flight routes on a map, not a traditional x-y plot

fig

import numpy as np
import plotly.graph_objects as go

# Define cities with their coordinates (latitude, longitude)
cities = {
    'New York': (40.7128, -74.0060),
    'London': (51.5074, -0.1278),
    'Tokyo': (35.6762, 139.6503),
    'Sydney': (-33.8688, 151.2093),
    'Paris': (48.8566, 2.3522),
    'Dubai': (25.2048, 55.2708),
    'Singapore': (1.3521, 103.8198),
    'Hong Kong': (22.3193, 114.1694),
    'Los Angeles': (34.0522, -118.2437),
    'Mumbai': (19.0760, 72.8777)
}

# Create figure
fig = go.Figure()

# Add flight paths from New York to other cities
for city, (lat, lon) in cities.items():
    if city == 'New York':
        continue
    
    # Create curved flight path
    lat1, lon1 = cities['New York']
    lat2, lon2 = lat, lon
    
    # Convert to radians for calculation
    lat1, lon1 = np.radians(lat1), np.radians(lon1)
    lat2, lon2 = np.radians(lat2), np.radians(lon2)
    
    # Create intermediate points for the curve
    num_points = 50
    lats = []
    lons = []
    
    for i in range(num_points):
        xi = i / (num_points - 1)
        
        # Linear interpolation with slight arc
        lat_interp = lat1 + (lat2 - lat1) * xi
        lon_interp = lon1 + (lon2 - lon1) * xi
        
        # Add some curvature to make it look like a flight path
        arc_height = 0.3 * np.sin(np.pi * xi)
        lat_interp += arc_height * (lat2 - lat1) / abs(lat2 - lat1 + 0.001)
        
        lats.append(np.degrees(lat_interp))
        lons.append(np.degrees(lon_interp))
    
    fig.add_trace(go.Scattergeo(
        lat=lats,
        lon=lons,
        mode='lines',
        line=dict(width=1, color='blue'),
        opacity=0.6,
        showlegend=False
    ))

# Add city markers
for city, (lat, lon) in cities.items():
    if city == 'New York':
        color = 'red'
        size = 12
    else:
        color = 'blue'
        size = 8
    
    fig.add_trace(go.Scattergeo(
        lat=[lat],
        lon=[lon],
        mode='markers',
        marker=dict(
            size=size,
            color=color,
            symbol='circle'
        ),
        text=city,
        name=city,
        showlegend=False
    ))

# Update layout
fig.update_layout(
    title='Flight Routes from New York to Major Cities',
    geo=dict(
        scope='world',
        projection_type='natural earth',
        showland=True,
        landcolor='lightgray',
        showocean=True,
        oceancolor='lightblue',
        showcountries=True,
        countrycolor='white'
    ),
    width=1000,
    height=600,
    margin=dict(l=0, r=0, t=50, b=0)
)

# Add annotation for New York
fig.add_annotation(
    x=cities['New York'][1],
    y=cities['New York'][0],
    text='New York (Hub)',
    showarrow=True,
    arrowhead=2,
    arrowsize=1,
    arrowwidth=2,
    arrowcolor='red'
)

# Generate x-values for the specified range (though not used in geographic plot)
x_values = np.linspace(-10.0, 10.0, 100)

# The x_values are generated as requested but not used in this geographic visualization
# since we're plotting flight routes on a map, not a traditional x-y plot

# Display the figure
fig.show()
# END-OF-CODE

Opens the Analyze page with this code pre-loaded and ready to execute

Common Use Cases

  • 1Airline route network visualization
  • 2Trade flow between countries
  • 3Migration pattern analysis
  • 4Supply chain and logistics mapping

Pro Tips

Use great circle paths for accurate long-distance routes

Vary line thickness based on flow volume

Add animation for directional flows

Free Cheat Sheet

Scientific Chart Selection Cheat Sheet

Not sure whether to use a Violin Plot, Box Plot, or Ridge Plot? Download our single-page reference mapping the most-used scientific chart types, exactly when to use them, and the core Matplotlib/Seaborn functions.

Comparison Charts
Distribution Charts
Time Series Data
Common Mistakes
No spam. Unsubscribe anytime.