Skip to content

Commit

Permalink
Added gallery entries for Chord
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 29, 2018
1 parent 4c589c2 commit b259ef3
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 0 deletions.
89 changes: 89 additions & 0 deletions examples/gallery/demos/bokeh/route_chord.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most examples work across multiple plotting backends equivalent, 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 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('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": [
"%%opts Chord [edge_color_index='SourceID' label_index='City' color_index='AirportID' width=800 height=800]\n",
"%%opts Chord (cmap='Category20' edge_cmap='Category20')\n",
"busiest_airports"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
90 changes: 90 additions & 0 deletions examples/gallery/demos/matplotlib/route_chord.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most examples work across multiple plotting backends equivalent, 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' width=800 height=800]\n",
"%%opts Chord (cmap='Category20' edge_cmap='Category20')\n",
"busiest_airports"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit b259ef3

Please sign in to comment.