问题描述
参考
https://docs.bokeh.org/en/latest/docs/gallery/range_tool.html
您可以使用范围工具控制顶部的主要图表。
您可以修改它,以便选择多个图表吗?到目前为止,我尝试显示的是图表,但只有与x_range
同步的图表才是移动的图表。我试图通过一个列表,一系列,没有用。有人可以协助吗?
示例代码:
import numpy as np
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource,Rangetool
from bokeh.plotting import figure
from bokeh.sampledata.stocks import AAPL,GOOG
from bokeh.layouts import gridplot
dates = np.array(AAPL['date'],dtype=np.datetime64)
source = ColumnDataSource(data=dict(date=dates,aapl=AAPL['adj_close'],goog=GOOG['adj_close']))
p1 = figure(plot_height=300,plot_width=800,tools="xpan",toolbar_location=None,x_axis_type="datetime",x_axis_location="above",background_fill_color="#efefef",x_range=(dates[1500],dates[2500]))
p1.line('date','aapl',source=source)
p1.yaxis.axis_label = 'Price'
p2 = figure(plot_height=300,dates[2500]))
p2.line('date','goog',source=source)
p2.yaxis.axis_label = 'Price'
p = gridplot([[p1,p2]])
select = figure(title="Drag the middle and edges of the selection Box to change the range above",plot_height=130,plot_width=1600,y_range=p1.y_range,y_axis_type=None,tools="",background_fill_color="#efefef")
range_tool = Rangetool(x_range=p1.x_range)
range_tool.overlay.fill_color = "navy"
range_tool.overlay.fill_alpha = 0.2
select.line('date',source=source)
select.line('date',source=source)
select.ygrid.grid_line_color = None
select.add_tools(range_tool)
select.toolbar.active_multi = range_tool
show(column(p,select))
输出:
解决方法
您还必须配置所有要同步的绘图,并以相同的范围进行配置。
p2 = figure(...,x_range=p1.x_range)