[英]why I couldn't makes points shown on bokeh map in python?
我正在嘗試在Bokeh的地圖上繪制一些數據點,但不知何故,僅顯示地圖背景。
import pandas as pd
from IPython.core.display import HTML, display
%matplotlib inline
sample = pd.DataFrame({'Lat': [40.7260,40.7209], 'Lon': [-73.991,-74.0507], 'Count': 1})
from bokeh.plotting import figure, output_notebook, show
output_notebook()
from bokeh.tile_providers import STAMEN_TERRAIN
x_range, y_range = ((-8242000,-8210000), (4965000,4990000))
plot_width = int(750)
plot_height = int(plot_width//1.2)
def base_plot(tools='pan,wheel_zoom,reset',plot_width=plot_width, plot_height=plot_height, **plot_args):
p = figure(tools=tools, plot_width=plot_width, plot_height=plot_height,
x_range=x_range, y_range=y_range, outline_line_color=None,
min_border=0, min_border_left=0, min_border_right=0,
min_border_top=0, min_border_bottom=0, **plot_args)
p.axis.visible = False
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
return p
p = base_plot()
p.add_tile(STAMEN_TERRAIN)
p.circle(x=samples['Lat'], y=samples['Lon'], **options)
show(p)
謝謝你的建議。
繪圖范圍以Web墨卡托單位為單位:
((-8242000,-8210000), (4965000,4990000))
但是sample
DataFrame中的數據點是以經/緯度為單位。 您可以:
以緯度/經度單位(匹配!)添加“額外范圍”,並讓p.circle
引用額外范圍而不是默認范圍。
將圓坐標轉換為Web Mercator
后者可能更容易。 該頁面具有可以進行轉換的功能。 使用它,您將得到
sample = pd.DataFrame({
'easting': [-8236640.443285105, -8243286.216885463],
'northing': [4972010.345629457, 4971261.231184175]
})
更新代碼以使用此代碼:
import pandas as pd
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.tile_providers import STAMEN_TERRAIN
samples = pd.DataFrame({
'easting': [-8236640.443285105, -8243286.216885463],
'northing': [4972010.345629457, 4971261.231184175]
})
x_range, y_range = ((-8242000,-8210000), (4965000,4990000))
plot_width = int(750)
plot_height = int(plot_width//1.2)
def base_plot(tools='pan,wheel_zoom,reset',plot_width=plot_width, plot_height=plot_height, **plot_args):
p = figure(tools=tools, plot_width=plot_width, plot_height=plot_height,
x_range=x_range, y_range=y_range, outline_line_color=None,
min_border=0, min_border_left=0, min_border_right=0,
min_border_top=0, min_border_bottom=0, **plot_args)
p.axis.visible = False
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
return p
p = base_plot()
p.add_tile(STAMEN_TERRAIN)
p.circle(x=samples['easting'], y=samples['northing'], size=20, color="red")
output_file("map.html")
show(p)
產生此圖:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.