如果我在 jupyter 实验室上运行这个例子就可以了
from bokeh.io import output_notebook, show, push_notebook
from bokeh.models import HoverTool, CustomJSHover
from bokeh.tile_providers import CARTODBPOSITRON
from bokeh.plotting import figure
output_notebook()
# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(CARTODBPOSITRON)
p.circle(x=[0, 2000000, 4000000], y=[4000000, 2000000, 0], size=30)
code = """
var projections = require("core/util/projections");
var x = special_vars.x
var y = special_vars.y
var coords = projections.wgs84_mercator.inverse([x, y])
return coords[%d].toFixed(2)
"""
p.add_tools(HoverTool(
tooltips=[
( 'lon', '@x{custom}' ),
( 'lat', '@y{custom}' ),
],
formatters={
'x' : CustomJSHover(code=code % 0),
'y' : CustomJSHover(code=code % 1),
}
))
show(p)
但是,如果我使用散景服务运行示例,我会收到错误消息Uncaught Error: Cannot find module 'core/util/projections'
from bokeh.io import curdoc
from bokeh.models import HoverTool, CustomJSHover
from bokeh.plotting import figure
from bokeh.tile_providers import CARTODBPOSITRON
# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(CARTODBPOSITRON)
p.circle(x=[0, 2000000, 4000000], y=[4000000, 2000000, 0], size=30)
code = """
var projections = require("core/util/projections");
var x = special_vars.x
var y = special_vars.y
var coords = projections.wgs84_mercator.inverse([x, y])
return coords[%d].toFixed(2)
"""
p.add_tools(HoverTool(
tooltips=[
( 'lon', '@x{custom}' ),
( 'lat', '@y{custom}' ),
],
formatters={
'x' : CustomJSHover(code=code % 0),
'y' : CustomJSHover(code=code % 1),
}
))
curdoc().add_root(p)
我错过了什么吗?require
运行脚本时是否需要调整调用bokeh serve
?我在示例文件夹中没有看到任何带有散景服务的示例
我的版本
Python version : 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
IPython version : 6.5.0
Tornado version : 5.1
Bokeh version : 1.0.0dev8
node.js version : v8.11.3
10月9日更新
实际上,我已经从zip 版本编译并安装了 Bokeh 。我收到 404 错误,因为 js 文件的 url 是 url 与本地路径的串联
http://localhost:5006/static/js/C:/path_to_bokeh_folder/bokeh/bokehjs/node_modules/tslib/tslib.js
恐怕我在散景安装过程中做错了什么。我已遵循本指南
我正在使用 Windows 10
10月10日更新
感谢@Torus,我已经设置BOKEH_RESOURCES=server-dev
了环境变量,但也找不到该模块。
有关其他信息:我已经安装了散景:
python setup.py install --build-js
我已经设置了这个环境变量:
BOKEH_BROWSER=none
BOKEH_LOG_LEVEL=debug
BOKEH_MINIFIED=false
BOKEH_PRETTY=true
BOKEH_PY_LOG_LEVEL=debug
BOKEH_RESOURCES=server-dev # this is the most important as you pointed, to get the right paths
BOKEH_SIMPLE_IDS=true
但是我仍然遇到同样的错误,找不到模块:
Cannot find module 'core/util/projections'
结论
我认为手动构建散景时有问题,因为如果我以通常的方式安装它:pip install bokeh
,当我做的时候require("core/util/projections")
工作正常。
还有另一种方法可以将坐标转换为“墨卡托投影”吗?我应该创建另一个 CDS 列并在 python 中进行转换吗?