{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Map of the world's airports" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import plotly.plotly as py\n", "import numpy as np\n", "import pandas as pd\n", "import json" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01234567891011
0 1 Goroka Goroka Papua New Guinea GKA AYGA-6.081689 145.391881 5282 10 U Pacific/Port_Moresby
1 2 Madang Madang Papua New Guinea MAG AYMD-5.207083 145.788700 20 10 U Pacific/Port_Moresby
2 3 Mount Hagen Mount Hagen Papua New Guinea HGU AYMH-5.826789 144.295861 5388 10 U Pacific/Port_Moresby
3 4 Nadzab Nadzab Papua New Guinea LAE AYNZ-6.569828 146.726242 239 10 U Pacific/Port_Moresby
4 5 Port Moresby Jacksons Intl Port Moresby Papua New Guinea POM AYPY-9.443383 147.220050 146 10 U Pacific/Port_Moresby
\n", "

5 rows × 12 columns

\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 \\\n", "0 1 Goroka Goroka Papua New Guinea GKA AYGA \n", "1 2 Madang Madang Papua New Guinea MAG AYMD \n", "2 3 Mount Hagen Mount Hagen Papua New Guinea HGU AYMH \n", "3 4 Nadzab Nadzab Papua New Guinea LAE AYNZ \n", "4 5 Port Moresby Jacksons Intl Port Moresby Papua New Guinea POM AYPY \n", "\n", " 6 7 8 9 10 11 \n", "0 -6.081689 145.391881 5282 10 U Pacific/Port_Moresby \n", "1 -5.207083 145.788700 20 10 U Pacific/Port_Moresby \n", "2 -5.826789 144.295861 5388 10 U Pacific/Port_Moresby \n", "3 -6.569828 146.726242 239 10 U Pacific/Port_Moresby \n", "4 -9.443383 147.220050 146 10 U Pacific/Port_Moresby \n", "\n", "[5 rows x 12 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat', header=None)\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The longitudes are in column 7 and the latitudes in column 6." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(\n", " dict(\n", " data=[\n", " dict(\n", " type='scattergeo',\n", " lon=df.ix[:,7],\n", " lat=df.ix[:,6],\n", " text=df.apply(lambda row: str(row[1])+' ('+str(row[4])+')'+'
'+str(row[3]), axis=1),\n", " name='',\n", " marker=dict(\n", " opacity=0.4,\n", " line=dict(\n", " color='rgb(187,187,187)',\n", " width=0.5\n", " )\n", " )\n", " )\n", " ],\n", " layout=dict(\n", " title='Map of the world\\'s airports',\n", " titlefont=dict(\n", " size=24\n", " ),\n", " geo=dict(\n", " projection=dict(\n", " type='natural earth'\n", " ),\n", " showcountries=True\n", " )\n", " )\n", " ),\n", " validate=False,\n", " filename='airport',\n", " auto_open=False\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See the full-screen version at: [plot.ly/~etpinard/4288.embed](https://plot.ly/~etpinard/4288/map-of-the-worlds-airports.embed)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Inject CSS styling in the NB\n", "from IPython.display import display, HTML\n", "display(HTML(open('../_custom.css').read()))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }