以下代码适用于在Google地图图片上绘制圆圈。蓝色圆圈代表起源,红色圆圈代表目的地。数据来自csv文件,该文件导入到数据框中。数据包含10条路线的纬度/经度坐标。再次,我能够轻松地绘制代表位置的圆圈。但是,当我添加代码来绘制段(连接点的线)时,不会渲染任何内容。运行脚本时也没有报告错误,这使得诊断变得困难。我在代码中围绕与段相关的部分进行了注释。任何帮助,将不胜感激。
我使用的是Bokeh版本0.12.6和python 3.5
import pandas as pd
from bokeh.io import output_file, show
from bokeh.models import HoverTool, ResetTool, WheelZoomTool
from bokeh.models import GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d,PanTool, Segment
df = pd.read_csv('routes.csv', index_col='Lane')
map_options = GMapOptions(lat=40.29, lng=-97.73, map_type="roadmap", zoom=4)
plot = GMapPlot(x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options,plot_width=800, plot_height=700)
plot.title.text = "Top 10 Routes Over 500 miles"
plot.api_key = "MyKEY"
sourceO=ColumnDataSource(
data=dict(
lat=list(df.Originlat),
lon=list(df.Originlng),
desc=list(df.OriginCity)
)
)
sourceD=ColumnDataSource(
data=dict(
lat=list(df.Destlat),
lon=list(df.Destlng),
desc=list(df.DestCity)
)
)
#data for segments
sourceR=ColumnDataSource(
data=dict(
Originlat= list(df.Originlat),
Originlng=list(df.Originlng),
Destlat=list(df.Destlat),
Destlng=list(df.Destlng),
desc=list(df.index)
)
)
hover = HoverTool(tooltips=[
("", "@desc"),
])
circleO = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, line_color='black')
circleD = Circle(x="lon", y="lat", size=15, fill_color="red", fill_alpha=0.8, line_color='black')
#setting the segments
route = Segment(x0='Originlng', y0="Originlat",x1='Destlng', y1="Destlat",line_color="black", line_width=2)
plot.add_glyph(sourceO, circleO)
plot.add_glyph(sourceD, circleD)
#adding segments to plot
plot.add_glyph(sourceR, route)
plot.add_tools(ResetTool(), WheelZoomTool(), PanTool(), hover)
output_file("gmap_plot.html")
show(plot)