GMapPlot Bokeh Segments Not Displaying

The code below works well for building circles on a Google map image. Blue circles represent origin, and red circles represent destinations. The data comes from the csv file, which is imported into the dataframe. The data contains lat / lng coordinates for 10 routes. Again, I can easily draw circles representing locations. But when I add code to draw segments (lines connecting points), nothing is displayed. When running the script errors are not reported, which complicates the diagnosis. I made comments in code around segments related parts. Any help would be greatly appreciated.

I am using Bokeh version 0.12.6 and 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)
+4

Source: https://habr.com/ru/post/1681392/


All Articles