9

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

Joshin
  • 299
  • 1
  • 3
  • 14
  • I don't know what "bokeh" is, but as someone who works in GIS, what you're trying to is called adding a basemap. Hopefully, that will help your Google-fu. – jpmc26 Dec 21 '14 at 15:54
  • Bokeh is an open source, multi-language visualization library targeting the browser for interactive and streaming visualizations: http://bokeh.pydata.org – bigreddot Dec 22 '14 at 18:57

3 Answers3

9

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.

KT12
  • 549
  • 11
  • 24
tkchris
  • 125
  • 1
  • 7
3

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.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
1

Here's a link you might want to check:

https://docs.bokeh.org/en/0.11.0/docs/gallery/choropleth.html

from bokeh.sampledata import us_states, us_counties, unemployment
from bokeh.plotting import *

us_states = us_states.data.copy()
us_counties = us_counties.data.copy()
unemployment = unemployment.data

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

state_xs = [us_states[code]["lons"] for code in us_states]
state_ys = [us_states[code]["lats"] for code in us_states]

county_xs=[us_counties[code]["lons"] for code in us_counties if us_counties[code]["state"] not in ["ak", "hi", "pr", "gu", "vi", "mp", "as"]]
county_ys=[us_counties[code]["lats"] for code in us_counties if us_counties[code]["state"] not in ["ak", "hi", "pr", "gu", "vi", "mp", "as"]]

colors = ["#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043"]

county_colors = []
for county_id in us_counties:
    if us_counties[county_id]["state"] in ["ak", "hi", "pr", "gu", "vi", "mp", "as"]:
        continue
    try:
        rate = unemployment[county_id]
        idx = min(int(rate/2), 5)
        county_colors.append(colors[idx])
    except KeyError:
        county_colors.append("black")

output_file("choropleth.html", title="choropleth.py example")

p = figure(title="US Unemployment 2009", toolbar_location="left",
    plot_width=1100, plot_height=700)

p.patches(county_xs, county_ys, fill_color=county_colors, fill_alpha=0.7,
    line_color="white", line_width=0.5)
p.patches(state_xs, state_ys, fill_alpha=0.0,
    line_color="#884444", line_width=2)

show(p)

I haven't tried it yet but I guess you can use shape files to have more accurate maps if you want to.

What I've tried before is the basemap module..

gmagno
  • 1,770
  • 1
  • 19
  • 40
jtitusj
  • 3,046
  • 3
  • 24
  • 40