Last active
July 12, 2016 19:27
-
-
Save cenveoanalyst/8931355cd8ee7466808e0cc452666246 to your computer and use it in GitHub Desktop.
Example google maps showing nothing but pure whiteness in Jupyter Notebook
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from bokeh.io import output_notebook, show\n", | |
"from bokeh.models import (\n", | |
" GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool\n", | |
")\n", | |
"import bokeh\n", | |
"import pandas as pd\n", | |
"import pyodbc as pdb\n", | |
"import numpy as np\n", | |
"from IPython.display import HTML\n", | |
"from pandas import DataFrame\n", | |
"from bokeh.charts import Bar\n", | |
"from bokeh.plotting import figure, show, output_notebook\n", | |
"from numpy import nan\n", | |
"from bokeh import *\n", | |
"from bokeh.models import PrintfTickFormatter\n", | |
"from bokeh.models.formatters import NumeralTickFormatter, DatetimeTickFormatter\n", | |
"from prettypandas import PrettyPandas\n", | |
"import datetime\n", | |
"from bokeh.io import *\n", | |
"from bokeh.resources import INLINE" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"API_KEY = 'APIKEYHERE' " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Bokeh Documentation Example" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"map_options = GMapOptions(lat=30.29, lng=-97.73, map_type=\"hybrid\", zoom=11)\n", | |
"\n", | |
"plot = GMapPlot(\n", | |
" x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY\n", | |
")\n", | |
"plot.title.text = \"Austin\"\n", | |
"\n", | |
"plot = GMapPlot(\n", | |
" x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY\n", | |
")\n", | |
"plot.title.text = \"Austin\"\n", | |
"\n", | |
"source = ColumnDataSource(\n", | |
" data=dict(\n", | |
" lat=[30.29, 30.20, 30.29],\n", | |
" lon=[-97.70, -97.74, -97.78],\n", | |
" )\n", | |
")\n", | |
"\n", | |
"circle = Circle(x=\"lon\", y=\"lat\", size=15, fill_color=\"blue\", fill_alpha=0.8, line_color='black')\n", | |
"plot.add_glyph(source, circle)\n", | |
"\n", | |
"plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"output_notebook(resources=INLINE)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"show(plot)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The first instance of calling a Google Map plot after the notebook has opened exactly the first time will work for this example, but the second will produce first a white plot overlayed with the points specified; then a pure white plot showing nothing. " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Attempted Other Example- Customer Ship to Locations on Map of US" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"customerlatys = [ -93.4530273, -93.4530273, -81.3948073, -70.315439 ,\n", | |
" -83.13046 , -84.0084598, -81.3946961, -97.0175879,\n", | |
" -94.798801 , -122.2425556, -84.0043513, -115.0734823,\n", | |
" -80.3694894, -74.8953228, -118.1524542, -118.1524542,\n", | |
" -118.1505045, -104.8647567, -104.868137 , -84.4672565,\n", | |
" -88.1017695, -112.1962611, -95.5359246, -80.1201124,\n", | |
" -94.5049029, -121.9792064, -122.2466857, -76.0044851,\n", | |
" -118.0045496, -96.997643 , -88.0258922, -90.2384679,\n", | |
" -77.3514688, -81.6966306, -117.962364 , -117.962364 ]\n", | |
"customerlongxs = [ 44.9907302, 44.9907302, 28.4370887, 43.702585 , 39.92624 ,\n", | |
" 34.1063354, 28.4126344, 32.7811446, 39.05919 , 47.2328869,\n", | |
" 34.1206564, 36.2125289, 26.0959809, 40.1152807, 33.8029853,\n", | |
" 33.8029853, 33.8030592, 39.7809048, 39.782005 , 39.3197423,\n", | |
" 41.9101488, 33.4418136, 29.8596662, 26.4047631, 39.1284833,\n", | |
" 37.4986612, 47.4072455, 40.9998451, 33.7863434, 32.797557 ,\n", | |
" 41.9762586, 32.3420018, 40.119181 , 30.3617348, 33.8726385,\n", | |
" 33.8726385]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"mapoptions2 = GMapOptions(lat=39.8282, lng=-98.5795, map_type = 'roadmap', zoom = 5)\n", | |
"testmapplot = GMapPlot(\n", | |
" x_range=DataRange1d(), y_range=DataRange1d(), map_options=mapoptions2, api_key=API_KEY\n", | |
")\n", | |
"testmapplot.title.text = \"Customer Ship To Locations Over Test map\"\n", | |
"\n", | |
"source = ColumnDataSource(\n", | |
" data=dict(\n", | |
" lat=customerlatys,\n", | |
" lon=customerlongxs,\n", | |
" )\n", | |
")\n", | |
"\n", | |
"circle = Circle(x=\"lon\", y=\"lat\", size=15, fill_color='#89169f', fill_alpha=0.8, line_color='black')\n", | |
"testmapplot.add_glyph(source, circle)\n", | |
"testmapplot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"show(testmapplot)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This example first shows the dots then immediately transitions to a pure white chart showing nothing. " | |
] | |
} | |
], | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment