This is a test of the pelican plugin for displaying a Jupyter notebook on this blog.

Plotting a Map in Bokeh with OpenStreetMap Tiles

Here is a map of the world plotted with OpenStreetMap tiles using the Python visualization tool Bokeh and this example code .

In [1]:
from bokeh.plotting import output_notebook, show

from bokeh.models import Plot
from bokeh.models import Range1d
from bokeh.models import WheelZoomTool, ResizeTool, PanTool, BoxZoomTool
from bokeh.models import WMTSTileSource

output_notebook()

# set to roughly full extent of web mercator projection
x_range = Range1d(start=-20000000, end=20000000)
y_range = Range1d(start=-20000000, end=20000000)

# create tile source from templated url
tile_options = {}
tile_options['url'] = 'http://c.tile.openstreetmap.org/{z}/{x}/{y}.png'.decode('utf-8')
tile_source = WMTSTileSource(**tile_options)

# instantiate plot and add tile source
p = Plot(x_range=x_range, y_range=y_range, plot_height=800, plot_width=800)
p.add_tools(ResizeTool(), WheelZoomTool(), PanTool(), BoxZoomTool())

tile_renderer_options = {}
p.add_tile(tile_source, **tile_renderer_options)

show(p)
BokehJS successfully loaded.
Out[1]:
<bokeh.io._CommsHandle at 0x10be0a1d0>
In [ ]: