{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most examples work across multiple plotting backends. This example is also available for:\n",
    "\n",
    "* [Bokeh - route_chord](../bokeh/route_chord.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import holoviews as hv\n",
    "from bokeh.sampledata.airport_routes import routes, airports\n",
    "\n",
    "hv.extension('matplotlib')\n",
    "%output fig='svg' size=300"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Declare data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Count the routes between Airports\n",
    "route_counts = routes.groupby(['SourceID', 'DestinationID']).Stops.count().reset_index()\n",
    "nodes = hv.Dataset(airports, 'AirportID', 'City')\n",
    "chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])\n",
    "\n",
    "# Select the 20 busiest airports\n",
    "busiest = list(routes.groupby('SourceID').count().sort_values('Stops').iloc[-20:].index.values)\n",
    "busiest_airports = chord.select(AirportID=busiest, selection_mode='nodes')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Chord [edge_color_index='SourceID' label_index='City' color_index='AirportID']\n",
    "%%opts Chord (cmap='Category20' edge_cmap='Category20')\n",
    "busiest_airports"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
