I can add a range tool to one chart like the example range_tool.py (range_tool.py — Bokeh 2.4.2 Documentation)
But when I create common-x-axis multichart first, and then want to add range tool to them, I don’t know how to set RangeTool(x_range=???)
Below is my code
from bokeh.io import show
from bokeh.models import ColumnDataSource, RangeTool,DataRange1d
from bokeh.plotting import figure
from bokeh.layouts import gridplot
x = [1,2,3,4,5,6,7,8,9,10]
y1 = [4,5,6,4,8,9,5,6,4,5]
y2 = [3,5,6,8,7,5,9,2,4,5]
source = ColumnDataSource(data=dict(x=x, y1=y1, y2=y2))
xdr = DataRange1d(bounds=None)
p1 = figure(plot_height=300, plot_width=800, tools="xpan", toolbar_location=None,
x_axis_location="above", background_fill_color="#efefef", x_range=xdr)
p1.line('x', 'y1', source=source, legend_label='y1', color="#2874A6")
p2 = figure(plot_height=100, plot_width=800, tools="", toolbar_location=None,
x_axis_location="above",background_fill_color="#efefef", x_range=xdr)
p2.line('x', 'y2', source=source, legend_label='y2', color="#2874A6")
select = figure(title="Drag the middle and edges of the selection box to change the range above",
plot_height=130, plot_width=800, y_range=p1.y_range, y_axis_type=None,
tools="", toolbar_location=None, background_fill_color="#efefef")
range_tool = RangeTool(x_range=None)
select.line('x', 'y1', source=source, color="#2874A6")
select.ygrid.grid_line_color = None
select.add_tools(range_tool)
select.toolbar.active_multi = range_tool
show(gridplot([p1,p2,select], ncols=1))
and below is the result
I don’t know how to set RangeTool(x_range= ), so I set None. I don’t know how to resolve it. Anyone can help me? Thanks!