-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba33edf
commit 732a35e
Showing
17 changed files
with
1,431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"from bokeh.sampledata.airport_routes import airports, routes\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Count the number of connections from each airport\n", | ||
"counts = routes.groupby('SourceID')[['Stops']].count().reset_index().rename(columns={'Stops': 'Connections'})\n", | ||
"airports_df = pd.merge(airports, counts, left_on='AirportID', right_on='SourceID', how='left')\n", | ||
"\n", | ||
"# Select only US mainland airports & convert from Mercator to Latitudes/Longitudes\n", | ||
"airport_points = gv.Points(airports_df, ['Longitude', 'Latitude']).select(Longitude=(-170, -50), Latitude=(0, 50))\n", | ||
"\n", | ||
"# Declare nodes, graph and tiles\n", | ||
"nodes = gv.Nodes(airport_points, ['Longitude', 'Latitude', 'AirportID'],\n", | ||
" ['Name', 'City', 'Connections'])\n", | ||
"graph = gv.Graph((routes, nodes), ['SourceID', 'DestinationID'], ['Source', 'Destination'])\n", | ||
"tiles = gv.WMTS('https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png')\n", | ||
"\n", | ||
"# Select 50 busiest airports\n", | ||
"busiest = list(routes.groupby('SourceID').count().sort_values('Stops').iloc[-50:].index.values)\n", | ||
"busiest_airports = graph.select(AirportID=busiest, selection_mode='nodes')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts Graph [width=800 height=600] (edge_selection_line_color='black' edge_hover_line_color='red')\n", | ||
"%%opts Graph (edge_line_width=1 edge_line_alpha=0.01 edge_nonselection_line_alpha=0.01)\n", | ||
"tiles * 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import geopandas as gpd\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Declaring data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"geometries = gpd.read_file('../../user_guide/assets/boundaries/boundaries.shp')\n", | ||
"referendum = pd.read_csv('../../user_guide/assets/referendum.csv')\n", | ||
"gdf = gpd.GeoDataFrame(pd.merge(geometries, referendum))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot_opts = dict(tools=['hover'], width=550, height=700, color_index='leaveVoteshare',\n", | ||
" colorbar=True, toolbar='above', xaxis=None, yaxis=None)\n", | ||
"gv.Polygons(gdf, vdims=['name', 'leaveVoteshare'], label='Brexit Referendum Vote').opts(plot=plot_opts)" | ||
] | ||
} | ||
], | ||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"import geoviews.feature as gf\n", | ||
"import cartopy.crs as ccrs\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def sample_data(shape=(73, 145)):\n", | ||
" \"\"\"Returns ``lons``, ``lats`` and ``data`` of some fake data.\"\"\"\n", | ||
" nlats, nlons = shape\n", | ||
" ys = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n", | ||
" xs = np.linspace(0, 2 * np.pi, nlons)\n", | ||
" lons, lats = np.meshgrid(xs, ys)\n", | ||
" wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n", | ||
" mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n", | ||
"\n", | ||
" lats = np.rad2deg(ys)\n", | ||
" lons = np.rad2deg(xs)\n", | ||
" data = wave + mean\n", | ||
"\n", | ||
" return lons, lats, data\n", | ||
"\n", | ||
"lons, lats, data = sample_data()\n", | ||
"contours = hv.operation.contours(gv.Image((lons, lats, data)),\n", | ||
" filled=True, levels=8).redim.range(z=(-1, 1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts Polygons [colorbar=True width=600 height=400] (cmap='nipy_spectral') \n", | ||
"contours * gf.coastline" | ||
] | ||
} | ||
], | ||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import geopandas as gpd\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"import cartopy.crs as ccrs\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"tiles = gv.WMTS('https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png')\n", | ||
"\n", | ||
"# Project data to Web Mercator\n", | ||
"nybb = gpd.read_file(gpd.datasets.get_path('nybb'))\n", | ||
"poly_data = nybb.to_crs(ccrs.GOOGLE_MERCATOR.proj4_init)\n", | ||
"polys = gv.Polygons(poly_data, vdims=['BoroName'], crs=ccrs.GOOGLE_MERCATOR)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts Polygons [width=800 height=600 color_index='BoroName' tools=['hover', 'tap']] (cmap='Category20')\n", | ||
"tiles * polys" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"from bokeh.tile_providers import STAMEN_TONER\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"openmap = 'http://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png'\n", | ||
"esri = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg'\n", | ||
"wiki = 'https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png'\n", | ||
"toner = STAMEN_TONER.url" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts WMTS [width=400 height=400 xaxis=None yaxis=None] (level='annotation')\n", | ||
"hv.Layout([gv.WMTS(tiles) for tiles in [openmap, esri, wiki, toner]]).cols(2)" | ||
] | ||
} | ||
], | ||
"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 | ||
} |
Oops, something went wrong.