[英]'Invalid value for 'x_range' Bokeh Gmap error
The code below is giving me the following error: 下面的代码给我以下错误:
ValueError: Invalid value for 'x_range', MapPlot ranges may only be Range1d, not data ranges
I'm almost certain there's nothing wrong with the code considering I had it working with no errors up until today. 我几乎可以肯定代码没有问题,因为直到今天我都可以正常工作。
I don't think this is relevant, but it stopped working after I ran the following in my command terminal: 我认为这无关紧要,但是在命令终端中运行以下命令后,它停止了工作:
sudo lsof -t -i tcp:5000 -s tcp:listen | sudo xargs kill
I restarted my computer several times (in hopes of reseting the ports) but that hasn't worked either. 我几次重新启动计算机(以希望重置端口),但这也没有用。
My code is below: 我的代码如下:
from bokeh.models import (
GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool,
WheelZoomTool, BoxSelectTool
)
from bokeh.io import output_file, show, output_notebook
output_notebook()
map_options = GMapOptions(lat=30.29, lng=-97.73, map_type="roadmap", zoom=11)
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options
)
plot.title.text = "Austin"
plot.api_key = "INSERT PERSONAL GOOGLE API KEY"
completed_lats = [30.265872,30.2900002]
completed_longs = [-97.749270,-97.733322]
completed_source = ColumnDataSource( data=dict(
lat=completed_lats,
lon=completed_longs,))
completed_dots = Circle(x="lon", y="lat", size=50, fill_color="blue",
fill_alpha=0.1, line_color=None)
plot.add_glyph(completed_source, completed_dots)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
show(plot)
There is in fact a problem with the code, it is this: 代码实际上存在问题,它是这样的:
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), # BAD
map_options=map_options
)
Exactly as the message states, only Range1d
can be used with GMapPlot
. 与消息状态完全一样,只有Range1d
可以与GMapPlot
一起使用。 This is because unlike regular Bokeh plots, Google Maps maintains complete control of the plot's axes dimensions. 这是因为与常规的Bokeh图不同,Google Maps可以完全控制图的轴尺寸。 This is inconsistent with using a DataRange1d
, because those also try to control the axes dimensions, which can lead to unpredictable and undesirable results. 这与使用DataRange1d
不一致,因为它们也试图控制轴的尺寸,这可能导致不可预测的不良结果。
There was a time before Bokeh checked for this, and would allow DataRange1d
to be passed. 散景检查之前有一段时间,它将允许传递DataRange1d
。 Once it was discovered that combination was causing problems, a check was added to explicitly disallow it. 一旦发现组合引起问题,便添加了检查以明确禁止组合。 You just need to use a Range1d
instead (you don't need to set start
or end
): 您只需要使用Range1d
(无需设置start
或end
):
plot = GMapPlot(
x_range=Range1d(), y_range=Range1d(), # GOOD
map_options=map_options
)
However, I should also point you to the gmap
function, which makes creating Google Maps plots much simpler . 但是,我也应该指出gmap
函数,该函数使创建Google Maps地图变得更加简单 。 With that it is much like figure
in that a reasonable default plot is created automatically, no need to create and add ranges at all. 与它很像figure
在一个合理的默认打印,会自动建立,无需创建并添加范围的。 It was announced in version 0.12.5 . 它在版本0.12.5中宣布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.