Airport Graph#

Download this notebook from GitHub (right-click to download).

import pandas as pd
import geoviews as gv
import geoviews.feature as gf
from bokeh.sampledata.airport_routes import airports, routes



Define data#

# Count the number of connections from each airport
counts = routes.groupby('SourceID')[['Stops']].count().reset_index().rename(columns={'Stops': 'Connections'})
airports_df = pd.merge(airports, counts, left_on='AirportID', right_on='SourceID', how='left')

# Select only US mainland airports & convert from Mercator to Latitudes/Longitudes
airport_points = gv.Points(airports_df, ['Longitude', 'Latitude'])[-170:-50, 0: 50]

# Declare nodes, graph and tiles
nodes = gv.Nodes(airport_points, ['Longitude', 'Latitude', 'AirportID'],
                 ['Name', 'City', 'Connections'])
graph = gv.Graph((routes, nodes), ['SourceID', 'DestinationID'], ['Source', 'Destination'])
tiles = gv.tile_sources.OSM

# Select 50 busiest airports
busiest = list(routes.groupby('SourceID').count().sort_values('Stops').iloc[-50:].index.values)
busiest_airports =, selection_mode='nodes')


gf.ocean * * gf.coastline * gf.borders * busiest_airports.opts(
    node_size=8, edge_linewidth=1, edge_alpha=0.05, fig_size=300, padding=0.1)