本文整理汇总了Python中bokeh.models.GMapPlot.add_layout方法的典型用法代码示例。如果您正苦于以下问题:Python GMapPlot.add_layout方法的具体用法?Python GMapPlot.add_layout怎么用?Python GMapPlot.add_layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.models.GMapPlot
的用法示例。
在下文中一共展示了GMapPlot.add_layout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trail_map
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def trail_map(data):
lon = (min(data.lon) + max(data.lon))/2
lat = (min(data.lat) + max(data.lat))/2
map_options = GMapOptions(lng=lon, lat=lat, zoom=13)
plot = GMapPlot(title="%s - Trail Map" % title, map_options=map_options, plot_width=800, plot_height=800)
xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')
xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker, grid_line_dash="dashed", grid_line_color="gray")
ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker, grid_line_dash="dashed", grid_line_color="gray")
plot.renderers.extend([xgrid, ygrid])
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool(), BoxSelectTool())
line_source = ColumnDataSource(dict(x=data.lon, y=data.lat, dist=data.dist))
line = Line(x="x", y="y", line_color="blue", line_width=2)
plot.add_glyph(line_source, line)
plot.x_range = DataRange1d(sources=[line_source.columns("x")])
plot.y_range = DataRange1d(sources=[line_source.columns("y")])
return plot
示例2: create_map_plot
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def create_map_plot(self):
lat=39.8282
lng=-98.5795
zoom=6
xr = Range1d()
yr = Range1d()
x_range = xr
y_range = yr
#map_options = GMapOptions(lat=39.8282, lng=-98.5795, zoom=6)
map_options = GMapOptions(lat=lat, lng=lng, zoom=zoom)
#map_options = GMapOptions(lat=30.2861, lng=-97.7394, zoom=15)
plot = GMapPlot(
x_range=x_range, y_range=y_range,
map_options=map_options,
plot_width=680,
plot_height=600,
title=" "
)
plot.map_options.map_type="hybrid"
xaxis = LinearAxis(axis_label="lon", major_tick_in=0, formatter=NumeralTickFormatter(format="0.000"))
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(axis_label="lat", major_tick_in=0, formatter=PrintfTickFormatter(format="%.3f"))
plot.add_layout(yaxis, 'left')
self.plot = plot
示例3: drawMap
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def drawMap(title, datas):
"""
color : [(lat, lon)]
"""
lat = []
lon = []
c = []
for color in datas:
c_lat, c_lon = zip(*datas[color])
#print (c_lat)
lat.extend(map(float, c_lat))
lon.extend(map(float, c_lon))
c.extend([color]*len(datas[color]))
center_lat = np.median(lat)
center_lon = np.median(lon)
x_range = Range1d()
y_range = Range1d()
source = ColumnDataSource(
data=dict(
lat=lat,
lon=lon,
fill=c
)
)
map_options = GMapOptions(lat=center_lat, lng=center_lon, map_type="roadmap", zoom=11)
plot = GMapPlot(
x_range=x_range, y_range=y_range,
map_options=map_options,
title=title
)
# Glyphs (dots on graph)
circle = Circle(x="lon", y="lat", size=6, line_width=0, fill_color="fill", fill_alpha=0.5, line_alpha=0.0)
plot.add_glyph(source, circle)
#Navigation
pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()
plot.add_tools(pan, wheel_zoom, box_select)
overlay = BoxSelectionOverlay(tool=box_select)
plot.add_layout(overlay)
return display.HTML(file_html(plot, INLINE, "Google Maps Example"))
示例4: create_village_map
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def create_village_map(survey):
s = survey[["village_name", "_gps_point_latitude" , "_gps_point_longitude"]]
g = s.groupby("village_name")
mean = g.agg([np.mean])
mean = mean.reset_index()
mean.columns = ['_'.join(col).strip() for col in mean.columns.values]
mean.columns = ['vn', 'lat_mean', 'lon_mean']
x_range = Range1d()
y_range = Range1d()
map_options = GMapOptions(lat= -2.588, lng=140.5170, zoom=11)
plot = GMapPlot(
x_range = x_range,
y_range = y_range,
map_options=map_options,
title = "Lake Sentani"
)
dot_source = ColumnDataSource(
data=dict(
lat = [float(x) for x in survey['_gps_point_latitude']],
lon = [float(y) for y in survey['_gps_point_longitude']],
uuid = [str(x) for x in survey['_uuid']],
vName = [str(x) for x in survey['village_name']],
size = [.0001 for x in survey['_uuid']],
)
)
plot.map_options.map_type="terrain"
circle = Circle(x='lon', y='lat', radius='size', fill_color = 'red', fill_alpha = 0.9)
plot.add_glyph(dot_source, circle)
text_source = ColumnDataSource(
data=dict(
vn = [str(x) for x in mean['vn']],
lat = [float(x) for x in mean['lat_mean']],
lon = [float(x) for x in mean['lon_mean']]
)
)
text = Text(x="lon", y="lat", text="vn", text_color="maroon")
plot.add_glyph(text_source, text)
reset = ResetTool()
pan = PanTool()
wheel_zoom = WheelZoomTool()
box_zoom = BoxZoomTool()
plot.add_tools(pan, wheel_zoom, box_zoom, reset)
xaxis = LinearAxis(axis_label="lon.", major_tick_in=0)
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(axis_label="lat.", major_tick_in=0)
plot.add_layout(yaxis, 'left')
return plot
示例5: create_map_plot
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def create_map_plot(self):
lat=39.8282
lng=-98.5795
zoom=6
xr = Range1d()
yr = Range1d()
x_range = xr
y_range = yr
#map_options = GMapOptions(lat=39.8282, lng=-98.5795, zoom=6)
map_options = GMapOptions(lat=lat, lng=lng, zoom=zoom)
#map_options = GMapOptions(lat=30.2861, lng=-97.7394, zoom=15)
plot = GMapPlot(
x_range=x_range, y_range=y_range,
map_options=map_options,
title = "Hotel Review Explorer",
plot_width=680,
plot_height=600
)
plot.map_options.map_type="hybrid"
xaxis = LinearAxis(axis_label="lon", major_tick_in=0, formatter=NumeralTickFormatter(format="0.000"))
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(axis_label="lat", major_tick_in=0, formatter=PrintfTickFormatter(format="%.3f"))
plot.add_layout(yaxis, 'left')
#pan = PanTool()
#wheel_zoom = WheelZoomTool()
#box_select = BoxSelectTool()
#box_select.renderers = [rndr]
#tooltips = "@name"
#tooltips = "<span class='tooltip-text'>@names</span>\n<br>"
#tooltips += "<span class='tooltip-text'>Reviews: @num_reviews</span>"
#hover = HoverTool(tooltips="@num_reviews")
#hover = HoverTool(tooltips="@names")
#hover = HoverTool(tooltips=tooltips)
#tap = TapTool()
#plot.add_tools(pan, wheel_zoom, box_select, hover, tap)
#plot.add_tools(hover, tap)
#overlay = BoxSelectionOverlay(tool=box_select)
#plot.add_layout(overlay)
#plot.add_glyph(self.source, circle)
#county_xs, county_ys = get_some_counties()
#apatch = Patch(x=county_xs, y=county_ys, fill_color=['white']*len(county_xs))
#plot.add_glyph(apatch)
self.plot = plot
示例6: trail_map
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def trail_map(data):
lon = (min(data.lon) + max(data.lon)) / 2
lat = (min(data.lat) + max(data.lat)) / 2
map_options = GMapOptions(lng=lon, lat=lat, zoom=13)
plot = GMapPlot(plot_width=800, plot_height=800, map_options=map_options, api_key=API_KEY)
plot.title.text = "%s - Trail Map" % name
plot.x_range = Range1d()
plot.y_range = Range1d()
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
line_source = ColumnDataSource(dict(x=data.lon, y=data.lat, dist=data.dist))
line = Line(x="x", y="y", line_color="blue", line_width=2)
plot.add_glyph(line_source, line)
if plot.api_key == "GOOGLE_API_KEY":
plot.add_layout(Label(x=240, y=700, x_units='screen', y_units='screen',
text='Replace GOOGLE_API_KEY with your own key',
text_color='red'))
return plot
示例7: ColumnDataSource
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
)
source = ColumnDataSource(
data=dict(
lat=[30.2861, 30.2855, 30.2869],
lon=[-97.7394, -97.7390, -97.7405],
fill=['orange', 'blue', 'green']
)
)
circle = Circle(x="lon", y="lat", size=15, fill_color="fill", line_color="black")
plot.add_glyph(source, circle)
pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()
plot.add_tools(pan, wheel_zoom, box_select)
overlay = BoxSelectionOverlay(tool=box_select)
plot.add_layout(overlay)
doc = Document()
doc.add_root(plot)
if __name__ == "__main__":
filename = "maps.html"
with open(filename, "w") as f:
f.write(file_html(doc, INLINE, "Google Maps Example"))
print("Wrote %s" % filename)
view(filename)
示例8: ColumnDataSource
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
)
plot.map_options.map_type="hybrid"
source = ColumnDataSource(data=data)
circle = Circle(x="lon", y="lat", size=10, line_color=None, fill_color='cyan', fill_alpha=0.1)
plot.add_glyph(source, circle)
pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()
plot.add_tools(pan, wheel_zoom, box_select)
xaxis = LinearAxis(axis_label="lon", major_tick_in=0, formatter=NumeralTickFormatter(format="0.000"))
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(axis_label="lat", major_tick_in=0, formatter=PrintfTickFormatter(format="%.3f"))
plot.add_layout(yaxis, 'left')
overlay = BoxSelectionOverlay(tool=box_select)
plot.add_layout(overlay)
doc = Document()
doc.add(plot)
if __name__ == "__main__":
filename = "maps_cities.html"
with open(filename, "w") as f:
f.write(file_html(doc, INLINE, "Google Maps All US cities Example"))
示例9: GMapOptions
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
map_options = GMapOptions(lat=15, lng=0, zoom=2)
plot = GMapPlot(
x_range=x_range,
y_range=y_range,
plot_width=1000,
plot_height=500,
map_options=map_options,
api_key=API_KEY,
webgl=True,
)
if plot.api_key == "GOOGLE_API_KEY":
plot.add_layout(Label(x=500, y=320, x_units='screen', y_units='screen',
text='Replace GOOGLE_API_KEY with your own key',
text_color='red', text_align='center'))
plot.title.text = "Cities of the world with a population over 5,000 people."
circle = Circle(x="lng", y="lat", size=5, line_color=None, fill_color='firebrick', fill_alpha=0.2)
plot.add_glyph(ColumnDataSource(data), circle)
plot.add_tools(PanTool(), WheelZoomTool())
doc = Document()
doc.add_root(plot)
if __name__ == "__main__":
doc.validate()
filename = "maps_cities.html"
with open(filename, "w") as f:
示例10: GMapOptions
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
from bokeh.resources import INLINE
# JSON style string taken from: https://snazzymaps.com/style/1/pale-dawn
map_options = GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=13, styles="""
[{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"on"},{"lightness":33}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2e5d4"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#c5dac6"}]},{"featureType":"poi.park","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":20}]},{"featureType":"road","elementType":"all","stylers":[{"lightness":20}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#c5c6c6"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#e4d7c6"}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#fbfaf7"}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"on"},{"color":"#acbcc9"}]}]
""")
# Google Maps now requires an API key. You can find out how to get one here:
# https://developers.google.com/maps/documentation/javascript/get-api-key
API_KEY = "GOOGLE_API_KEY"
plot = GMapPlot(map_options=map_options, api_key=API_KEY)
if plot.api_key == "GOOGLE_API_KEY":
plot.add_layout(Label(x=140, y=400, x_units='screen', y_units='screen',
text='Replace GOOGLE_API_KEY with your own key',
text_color='red'))
plot.title.text = "Austin"
source = ColumnDataSource(
data=dict(
lat=[30.2861, 30.2855, 30.2869],
lon=[-97.7394, -97.7390, -97.7405],
fill=['orange', 'blue', 'green']
)
)
circle = Circle(x="lon", y="lat", size=15, fill_color="fill", line_color="black")
plot.add_glyph(source, circle)
示例11: get_gmap_points
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def get_gmap_points():
'''Try to overlay a grid of points. This grid needs to scale with the
plot zoom, and move with the pan. Select points from poly, box, or lasso
Construct convex hull from points, overlay on plot
input hull coords to osm and download map
# plot extent?
https://github.com/bokeh/bokeh/blob/7cc925df6676e959f02d0842c5abb8cbdfab9df7/bokehjs/src/coffee/common/gmap_plot.coffee
!! Can't figure out what plot range is upon zoom! !!
Could also just use:
https://www.openstreetmap.org/export#map=13/38.8935/-77.0702
'''
# GOOGLE MAP
mapzoom = 14
x_mid, y_mid = -77.046998, 38.888214 # Washington DC
map_options = GMapOptions(lat=y_mid, lng=x_mid, zoom=mapzoom)
mapzoom = 14
#def center_coords():
# '''center map?'''
# global x_mid, y_mid
# return
title = 'Select Polygon'
htmlout = 'tst.html'
show = True
#################
# Box Select
source_rect_sel = ColumnDataSource(data=dict(x=[], y=[], width=[], height=[]))
rect_callback = Callback(args=dict(source=source_rect_sel), code="""
// get data source from Callback args
var data = source.get('data');
/// get BoxSelectTool dimensions from cb_data parameter of Callback
var geometry = cb_data['geometry'];
/// calculate Rect attributes
var width = geometry['x1'] - geometry['x0'];
var height = geometry['y1'] - geometry['y0'];
var x = geometry['x0'] + width/2;
var y = geometry['y0'] + height/2;
/// update data source with new Rect attributes (if we want multiple rects)
///data['x'].push(x);
///data['y'].push(y);
///data['width'].push(width);
///data['height'].push(height);
/// replace values
data['x'] = [x];
data['y'] = [y];
data['width'] = [width];
data['height'] = [height];
// trigger update of data source
source.trigger('change');
""")
box_select = BoxSelectTool(callback=rect_callback)
#################
# get gmap
# https://github.com/bokeh/bokeh/blob/master/examples/glyphs/maps.py
#https://github.com/bokeh/bokeh/blob/master/examples/glyphs/trail.py
# set map height, options
plot_height = int(0.75*plot_width)
map_options = GMapOptions(lat=y_mid, lng=x_mid, zoom=mapzoom)
x_range = Range1d()
y_range = Range1d()
plot = GMapPlot(x_range=x_range, y_range=y_range,
map_options=map_options,
plot_height=plot_height, plot_width=plot_width,
title=title)
plot.map_options.map_type='hybrid'
# !! Reset Tool goes to lat, lon = 0,0 !!
plot.add_tools(PanTool(), WheelZoomTool(), BoxZoomTool(), box_select,
PolySelectTool(),
LassoSelectTool(),
PreviewSaveTool(), ResizeTool())#, ResetTool())
# add axes
xaxis = LinearAxis(axis_label='Longitude')
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(axis_label='Latitude')
plot.add_layout(yaxis, 'left')
# add grid
xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker, \
grid_line_dash="dashed", grid_line_color="gray")
ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker, \
grid_line_dash="dashed", grid_line_color="gray")
plot.renderers.extend([xgrid, ygrid])
# add rect
rect = Rect(x='x',
y='y',
#.........这里部分代码省略.........
示例12: country_map
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def country_map(business, business_subset):
my_category = session['category_name']
if session['category_or_city'] == 'Category_typed':
my_category = session['category_typed']
lat_avg = business_subset['latitude'].mean()
lon_avg = business_subset['longitude'].mean()
my_lat = business_subset['latitude']
my_lon = business_subset['longitude']
my_stars = business_subset['stars']
star_avg = business_subset['stars'].mean()
my_colors_stars = list(map(map_star, my_stars))
my_lat = np.array(my_lat)
my_lon = np.array(my_lon)
my_stars = np.array(my_stars)
map_options = GMapOptions(lat=lat_avg, lng=lon_avg, map_type="roadmap", zoom=4)
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY
)
plot.title.text = 'Locations and Star ratings of ' + my_category + ' category. Average rating = ' + str(star_avg)
my_colors = my_colors_stars
source = ColumnDataSource( data=dict(lat = my_lat, lon = my_lon, stars = my_stars, the_colors=my_colors))
circle = Circle(x="lon", y="lat", size=5, fill_color="the_colors", fill_alpha=0.2, line_color=None)
plot.add_glyph(source, circle)
label1 = Label(x=410, y=530, x_units='screen', y_units='screen', text='green: 5 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label2 = Label(x=410, y=510, x_units='screen', y_units='screen', text='blue: 4 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label3 = Label(x=410, y=490, x_units='screen', y_units='screen', text='yellow: 3 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label4 = Label(x=410, y=470, x_units='screen', y_units='screen', text='red: < 2 stars', render_mode='css', border_line_color='white', background_fill_color='white')
plot.add_layout(label1)
plot.add_layout(label2)
plot.add_layout(label3)
plot.add_layout(label4)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
#################################################
#################################################
lat_avg = business['latitude'].mean()
lon_avg = business['longitude'].mean()
my_lat = business['latitude']
my_lon = business['longitude']
my_lat = np.array(my_lat)
my_lon = np.array(my_lon)
my_attributes = business['attributes_combined'].tolist()
my_colors_att = list(map(map_attribute, my_attributes))
my_colors = my_colors_att
plot2 = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY
)
plot2.title.text = 'Locations of Businesses with other Various Attributes'
source = ColumnDataSource( data=dict(lat = my_lat, lon = my_lon, stars = my_stars, the_colors=my_colors))
circle = Triangle(x="lon", y="lat", size=5, fill_color="the_colors", fill_alpha=0.2, line_color=None)
plot2.add_glyph(source, circle)
label1 = Label(x=410, y=530, x_units='screen', y_units='screen', text='green: casual', render_mode='css', border_line_color='white', background_fill_color='white')
label2 = Label(x=410, y=510, x_units='screen', y_units='screen', text='blue: upscale', render_mode='css', border_line_color='white', background_fill_color='white')
label3 = Label(x=410, y=490, x_units='screen', y_units='screen', text='yellow: touristy', render_mode='css', border_line_color='white', background_fill_color='white')
label4 = Label(x=410, y=470, x_units='screen', y_units='screen', text='red: hipster', render_mode='css', border_line_color='white', background_fill_color='white')
plot2.add_layout(label1)
plot2.add_layout(label2)
plot2.add_layout(label3)
plot2.add_layout(label4)
plot2.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
plots = row(plot, plot2)
script, div = components(plots)
return script, div
示例13: city_map
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
def city_map(business):
my_city = session['city_name']
business_subset = business[business['city'] == my_city]
lat_avg = business_subset['latitude'].mean()
lon_avg = business_subset['longitude'].mean()
my_lat = business_subset['latitude']
my_lon = business_subset['longitude']
my_stars = business_subset['stars']
star_avg = business_subset['stars'].mean()
my_colors_stars = list(map(map_star, my_stars))
my_lat = np.array(my_lat)
my_lon = np.array(my_lon)
my_stars = np.array(my_stars)
my_categories = business_subset['categories'].tolist()
my_colors_cuisine = list(map(map_cuisine, my_categories))
map_options = GMapOptions(lat=lat_avg, lng=lon_avg, map_type="roadmap", zoom=11)
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY
)
plot.title.text = my_city + ' business ratings. Average rating out of five stars = ' + str(star_avg)
my_colors = my_colors_stars
source = ColumnDataSource( data=dict(lat = my_lat, lon = my_lon, stars = my_stars, the_colors=my_colors))
circle = Circle(x="lon", y="lat", size=5, fill_color="the_colors", fill_alpha=0.2, line_color=None)
plot.add_glyph(source, circle)
label1 = Label(x=410, y=530, x_units='screen', y_units='screen', text='green: 5 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label2 = Label(x=410, y=510, x_units='screen', y_units='screen', text='blue: 4 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label3 = Label(x=410, y=490, x_units='screen', y_units='screen', text='yellow: 3 stars', render_mode='css', border_line_color='white', background_fill_color='white')
label4 = Label(x=410, y=470, x_units='screen', y_units='screen', text='red: < 2 stars', render_mode='css', border_line_color='white', background_fill_color='white')
plot.add_layout(label1)
plot.add_layout(label2)
plot.add_layout(label3)
plot.add_layout(label4)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
plot2 = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, api_key=API_KEY
)
plot2.title.text = my_city + ' locations of various cuisines'
my_colors = my_colors_cuisine
source = ColumnDataSource( data=dict(lat = my_lat, lon = my_lon, stars = my_stars, the_colors=my_colors))
circle = Triangle(x="lon", y="lat", size=5, fill_color="the_colors", fill_alpha=0.2, line_color=None)
plot2.add_glyph(source, circle)
label1 = Label(x=410, y=530, x_units='screen', y_units='screen', text='green: American', render_mode='css', border_line_color='white', background_fill_color='white')
label2 = Label(x=410, y=510, x_units='screen', y_units='screen', text='blue: Mexican', render_mode='css', border_line_color='white', background_fill_color='white')
label3 = Label(x=410, y=490, x_units='screen', y_units='screen', text='red: Italian', render_mode='css', border_line_color='white', background_fill_color='white')
label4 = Label(x=410, y=470, x_units='screen', y_units='screen', text='yellow: Chinese', render_mode='css', border_line_color='white', background_fill_color='white')
label5 = Label(x=410, y=450, x_units='screen', y_units='screen', text='brown: Japanese', render_mode='css', border_line_color='white', background_fill_color='white')
plot2.add_layout(label1)
plot2.add_layout(label2)
plot2.add_layout(label3)
plot2.add_layout(label4)
plot2.add_layout(label5)
plot2.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
plots = row(plot, plot2)
script, div = components(plots)
return script, div
示例14: ColumnDataSource
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
prost= ColumnDataSource(data=dict(lat=lat37,lon=lon37,cat=sfcat37['Category'],date=sfcat37['Dates']))
SUICIDE=ColumnDataSource(data=dict(lat=lat34,lon=lon34,cat=sfcat34['Category'],date=sfcat34['Dates']))
circle = Circle(x="lon", y="lat", size=4, fill_color="blue", fill_alpha=0.5, line_color=None)
circle2 = Circle(x="lon", y="lat", size=4, fill_color='red', fill_alpha=0.5, line_color=None)
circle34 = Circle(x="lon", y="lat", size=4, fill_color='lime', fill_alpha=0.5, line_color=None)
dui_plot=plot.add_glyph(dui, circle)
prost_plot=plot.add_glyph(prost, circle2)
suicide_plot=plot.add_glyph(SUICIDE, circle34)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool(),PreviewSaveTool(),HoverTool())
hover = plot.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [("Category", "@cat"),("Date", "@date"),("(Long, Lat)", "($x, $y)"),]
plot.add_layout(Legend(legends=[("PROSTITUTION", [prost_plot]),("DUI", [dui_plot]),("SUICIDE", [suicide_plot])]))
output_notebook()
#output_file("gmap_plot.html")
#show(plot)
#I don't show it because the file gets too big for displaying in my Git!
# ### Now Lets plot the weekly probability density distribution of these 3 crime categories.
# I used the data the whole city, and all years and months, just look at the occurence day and time of each crime.
# The result is interesting. Apparently, each day DUI peaks after midnight with the largest probability at Friday and Saturday. However, The peak of prostitution is during the week! The suicide has lower statistic. We still can see the peridoc behavior though. It is kind of surprising (to me at least) that the peak of the suicide is not during the dark hours!
# In[44]:
p1 = figure(width=900,height=660)#x_axis_type = "datetime")
p1.xaxis.axis_label ='Week Day'
示例15: index
# 需要导入模块: from bokeh.models import GMapPlot [as 别名]
# 或者: from bokeh.models.GMapPlot import add_layout [as 别名]
#.........这里部分代码省略.........
app.timeofday = app.timeofday +24
if app.direction == "from":
n0 = network_df[app.timeofday][my_center_id]
n0.sort(ascending=False,axis=1)
n0 = n0.irow(range(20))
elif app.direction == "to":
n0 = network_df[app.timeofday][:,my_center_id]
n0.sort(ascending=False,axis=1)
n0 = n0.irow(range(20))
#widths = [9,8,8,7,6,5,4,3,2,1]
ww = 0.
for index, row in n0.iteritems():
ww += 0.3
#p_i = get_center_coordinates(my_center_id,x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max,mesh_space=mesh_space)
p_f = get_center_coordinates(index,x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max,mesh_space=mesh_space)
ss = ColumnDataSource(
data=dict(
lat=[my_latitude,p_f[1]],
lon=[my_longitude,p_f[0]],
))
line = Line(x="lon", y="lat", line_width=ww)
plot.add_glyph(ss, line)
pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()
plot.add_tools(pan, wheel_zoom, box_select)
#xaxis = LinearAxis(axis_label="lat", major_tick_in=0, formatter=NumeralTickFormatter(format="0.000"))
#plot.add_layout(xaxis, 'below')
#yaxis = LinearAxis(axis_label="lon", major_tick_in=0, formatter=PrintfTickFormatter(format="%.3f"))
#plot.add_layout(yaxis, 'left')
overlay = BoxSelectionOverlay(tool=box_select)
plot.add_layout(overlay)
app.script, app.div = components(plot)
##################################################
##################################################
##################################################
########Bokeh FIG block##############################
# select the tools we want
TOOLS="pan,wheel_zoom,box_zoom,reset,save"
#print datetime.datetime(hour=int(33)/2, minute=int(33)%2*30)
#print data_df.index
p1 = figure(tools=TOOLS, plot_width=400, plot_height=400, x_axis_label='Time',y_axis_label='Number of trips')#,x_axis_type='datetime')
p1.line((data_df.index)/2, data_df['number_of_pickups_at_time_slot'],line_width=2, color="blue", legend="Total number of pickups in NYC in a typical day")
p1.line((data_df.index)/2, data_df['number_of_dropoffs_at_time_slot'],line_width=2, color="red",legend="Total number of dropoffs in NYC in a typical day")
#p1.circle(dates, closing_prices, fill_color="red", size=6)
#plots = {'Red': p1}
#script_graph1, div_graph1 = components(plots)
#app.script_graph1 = script_graph1
#app.div_graph1 = div_graph1.values()[0]
##################################################
##################################################
###ADD plot of NUMBER OF TRIPS (PICK UP AND DROPOFF FROM LOCATION)
pickup_count = [0 for i in range(48)]
dropoff_count = [0 for i in range(48)]
for ind in network_df.index.levels[0]:
try:
pickup_count[ind] = network_df[ind][my_center_id].count()
except KeyError:
pass
try:
dropoff_count[ind] = network_df[ind][:,my_center_id].count()
except KeyError:
continue
TOOLS="pan,wheel_zoom,box_zoom,reset,save"
p2 = figure(tools=TOOLS, plot_width=400, plot_height=400, x_axis_label='Time',y_axis_label='Number of trips')#,x_axis_type='datetime')
p2.line(np.array(range(48))/2, pickup_count,line_width=2, color="blue", legend="Average pickups from your location")
p2.line(np.array(range(48))/2, dropoff_count,line_width=2, color="red",legend="Average dropoffs at your location")
#p1.circle(dates, closing_prices, fill_color="red", size=6)
#plots2 = {'Red': p2}
plots1and2 = gridplot([[p1, p2]])
script_graph2, div_graph2 = components(plots1and2)
app.script_graph2 = script_graph2
app.div_graph2 = div_graph2
return redirect('/graph_page')