gpt4 book ai didi

python - 如何同时显示两个 Bokeh 对象?

转载 作者:行者123 更新时间:2023-12-01 01:37:10 25 4
gpt4 key购买 nike

我正在尝试将 Bokeh vbar 与 RangeTool 一起使用。我尝试了许多不同的代码行,但这仍然不起作用。我不明白“浏览器”的错误

相同的代码适用于线条或散点

这是错误:

TypeError: argument of type 'Figure' is not iterable

这是下面的代码:

from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, RangeTool
from bokeh.plotting import figure
from bokeh.models import Range1d

x = [1,2,3,4,5,6,7,8]
wdth = [0.5 for x in range(0,8)]
top = [8,7,6,5,4,3,2,1]

sourceRT5 = ColumnDataSource(data=dict(x=x, width=wdth, top=top))
p = figure(plot_height=300, plot_width=800,
tools="", toolbar_location=None,
x_axis_type="linear")


p.vbar('x', 'width', 'top', bottom=0, line_color='dodgerblue',
fill_color="dodgerblue", legend='New Words',
source=sourceRT5)

p.yaxis.axis_label = 'Price'

select = figure(plot_height=50, plot_width=800, y_range=(0,10),
x_axis_type="linear", y_axis_type=None,
tools="", toolbar_location=None)

range_rool = RangeTool(x_range=Range1d(3,8))
range_rool.overlay.fill_color = "navy"
range_rool.overlay.fill_alpha = 0.2

select.vbar('x', 'width', 'top', source=sourceRT5)
select.ygrid.grid_line_color = None
select.add_tools(range_rool)
select.toolbar.active_multi = range_rool

show(p,select)

有关错误的更多信息:

File "FromInt.py", line 6433, in testrangeVBar
show(p,select)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bokeh/io/showing.py", line 137, in show
return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bokeh/io/showing.py", line 165, in _show_with_state
controller = get_browser_controller(browser=browser)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bokeh/util/browser.py", line 47, in get_browser_controller
controller = webbrowser.get(browser)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/webbrowser.py", line 34, in get
if '%s' in browser:
TypeError: argument of type 'Figure' is not iterable

最佳答案

您似乎正在尝试显示多个数字。 show接受一个应该显示的对象,第二个参数是应该使用哪个浏览器(例如 firefox、chrome、IE、vivaldi...)。当你写它与分散一起工作时,我猜它没有抛出错误,但实际上并没有工作。

Bokeh 有一些documentation on displaying multiple plots 。简而言之,您需要告诉它应该以哪种方式布局它。一个非常通用的函数是 layout :

from bokeh.layouts import layout
... # your code without show(...)
show(layout([p,select]))

关于python - 如何同时显示两个 Bokeh 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52287976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com