Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions examples/notebooks/multi-layer-example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"import pandas as pd\n",
"\n",
"from mapboxgl.map import Map\n",
"from mapboxgl.layers import CircleLayer, GraduatedCircleLayer\n",
"from mapboxgl.utils import *\n",
"\n",
"\n",
"# Must be a public token, starting with `pk`\n",
"token = os.getenv('MAPBOX_ACCESS_TOKEN')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load data from sample csv\n",
"data_url = 'https://raw.githubusercontent.com/mapbox/mapboxgl-jupyter/master/examples/data/points.csv'\n",
"df = pd.read_csv(data_url).round(3)\n",
"\n",
"df_to_geojson(df, \n",
" filename='../data/healthcare_points.geojson',\n",
" properties=['Avg Medicare Payments', 'Avg Covered Charges', 'date'], \n",
" lat='lat', \n",
" lon='lon', \n",
" precision=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"measure_color = 'Avg Covered Charges'\n",
"color_breaks = [round(df[measure_color].quantile(q=x*0.1), 2) for x in range(2, 10)]\n",
"color_stops = create_color_stops(color_breaks, colors='Blues')\n",
"\n",
"# Generate radius breaks from data domain and circle-radius range\n",
"measure_radius = 'Avg Medicare Payments'\n",
"radius_breaks = [round(df[measure_radius].quantile(q=x*0.1), 2) for x in range(2, 10)]\n",
"radius_stops = create_radius_stops(radius_breaks, 0.5, 10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Just show a map of the data\n",
"mv = Map(\n",
" access_token=token,\n",
" opacity=0.8,\n",
" center=(-96, 37.8),\n",
" zoom=3)\n",
"\n",
"viz = CircleLayer(\n",
" '../data/healthcare_points.geojson', \n",
" access_token=token, \n",
" radius=2)\n",
"\n",
"mv.add_layer(viz)\n",
"\n",
"mv.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Just show a map of the data\n",
"mv = Map(\n",
" access_token=token,\n",
" opacity=0.8,\n",
" center=(-96, 37.8),\n",
" zoom=3)\n",
"\n",
"viz = CircleLayer(\n",
" '../data/healthcare_points.geojson', \n",
" access_token=token, \n",
" radius=2)\n",
"\n",
"mv.add_layer(viz)\n",
"\n",
"viz2 = GraduatedCircleLayer(\n",
" '../data/healthcare_points.geojson', \n",
" access_token=token,\n",
" color_property=\"Avg Covered Charges\",\n",
" color_stops=color_stops,\n",
" radius_property=\"Avg Medicare Payments\",\n",
" radius_stops=radius_stops,\n",
" stroke_color='black',\n",
" stroke_width=0.5,\n",
" opacity=0.5,\n",
" below_layer='waterway-label')\n",
"\n",
"mv.add_layer(viz2)\n",
"\n",
"mv.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mv = Map(\n",
" access_token=token,\n",
" opacity=0.8,\n",
" center=(-96, 37.8),\n",
" zoom=3)\n",
"\n",
"mv.add_layer(viz2)\n",
"mv.add_layer(viz)\n",
"\n",
"mv.show()"
]
}
],
"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.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
44 changes: 42 additions & 2 deletions mapboxgl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
from .viz import CircleViz, GraduatedCircleViz, HeatmapViz, ClusteredCircleViz, ImageViz, RasterTilesViz, ChoroplethViz, LinestringViz
from .viz import (
CircleViz,
GraduatedCircleViz,
HeatmapViz,
ClusteredCircleViz,
ImageViz,
RasterTilesViz,
ChoroplethViz,
LinestringViz,
)

from .layers import (
CircleLayer,
GraduatedCircleLayer,
HeatmapLayer,
ClusteredCircleLayer,
ImageLayer,
RasterTilesLayer,
ChoroplethLayer,
LinestringLayer,
)

from .map import Map

__version__ = "0.9.0"
__all__ = ['CircleViz', 'GraduatedCircleViz', 'HeatmapViz', 'ClusteredCircleViz', 'ImageViz', 'RasterTilesViz', 'ChoroplethViz', 'LinestringViz']
__all__ = [
'CircleViz',
'GraduatedCircleViz',
'HeatmapViz',
'ClusteredCircleViz',
'ImageViz',
'RasterTilesViz',
'ChoroplethViz',
'LinestringViz',
'CircleLayer',
'GraduatedCircleLayer',
'HeatmapLayer',
'ClusteredCircleLayer',
'ImageLayer',
'RasterTilesLayer',
'ChoroplethLayer',
'LinestringLayer',
'Map',
]
Loading