{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Most examples work across multiple plotting backends. This example is also available for:\n", "\n", "* [Matplotlib - route_chord](../matplotlib/route_chord.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import holoviews as hv\n", "from holoviews import opts, dim\n", "from bokeh.sampledata.airport_routes import routes, airports\n", "\n", "hv.extension('bokeh')" ] }, { "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": [ "busiest_airports.opts(\n", " opts.Chord(cmap='Category20', edge_color=dim('SourceID').str(), \n", " height=800, labels='City', node_color=dim('AirportID').str(), width=800))" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }