Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using bokeh to plot on top of a map

Tags:

python

bokeh

So i'm trying to use bokeh to plot a set of geographical points (school locations to be exact). I can plot them using the lats and longs, but how can I overlay these points over an actual map? Is there a way to integrate bokeh with google maps or something?

Thanks

like image 436
Joshin Avatar asked Dec 21 '14 04:12

Joshin


2 Answers

I recognize that this thread is old, but I haven't found a super clear answer anywhere else, so hopefully this will help.

from bokeh.sampledata import us_states
from bokeh.plotting import *

us_states = us_states.data.copy()

del us_states["HI"]
del us_states["AK"]

# separate latitude and longitude points for the borders
#   of the states.
state_xs = [us_states[code]["lons"] for code in us_states]
state_ys = [us_states[code]["lats"] for code in us_states]

# init figure
p = figure(title="Plotting Points Example: The 5 Largest Cities in Texas", 
           toolbar_location="left", plot_width=1100, plot_height=700)

# Draw state lines
p.patches(state_xs, state_ys, fill_alpha=0.0,
    line_color="#884444", line_width=1.5)

#  Latitude and Longitude of 5 Cities
# ------------------------------------
# Austin, TX -------30.26° N, 97.74° W
# Dallas, TX -------32.77° N, 96.79° W
# Fort Worth, TX ---32.75° N, 97.33° W
# Houston, TX ------29.76° N, 95.36° W
# San Antonio, TX --29.42° N, 98.49° W

# Now group these values together into a lists of x (longitude) and y (latitude)
x = [-97.7431, -96.79, -97.33, -95.36, -98.49]
y = [30.26, 32.77, 32.75, 29.76, 29.42] 

# The scatter markers
p.circle(x, y, size=8, color='navy', alpha=1)

# output to static HTML file
output_file("texas.html")

# show results
show(p)

Plotting points like these are called "Scatter Markers" in Bokeh. For more information, see here.

like image 109
tkchris Avatar answered Sep 19 '22 09:09

tkchris


There is an example of integrating Bokeh with Google maps here:

http://docs.bokeh.org/en/latest/docs/user_guide/geo.html#google-maps

Right now (as of 0.7) you have to use the lower level interface but will be adding GMap options to the higher level APIs soon.

like image 34
bigreddot Avatar answered Sep 19 '22 09:09

bigreddot