Drawing flight routes with NetworkX

In this recipe, we load and visualize a dataset containing many flight routes and airports around the world (obtained from the OpenFlights website at https://openflights.org/data.html).

Getting ready

To draw the graph on a map, you need Cartopy, available at http://scitools.org.uk/cartopy/. You can install it with conda install -c conda-forge cartopy.

How to do it...

  1. Let's import a few packages:
    >>> import math
        import json
        import numpy as np
        import pandas as pd
        import networkx as nx
        import cartopy.crs as ccrs
        import matplotlib.pyplot as plt
        from IPython.display import Image
        %matplotlib inline
  2. We load the first dataset containing many flight routes:
    >>> names = ('airline,airline_id,' 'source,source_id,' 'dest,dest_id,' ...

Get IPython Interactive Computing and Visualization Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.