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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.