I have a Bokeh (3.4.3) server application with multiple figures, and I want to toggle on/off synchronization of their x axes. I am able to successfully synchronize them but not un-synchronize them. Is this possible?
from bokeh.models import CheckboxGroup, ColumnDataSource, DataRange1d, Range1d
from bokeh.plotting import figure, show
from bokeh.layouts import column
from bokeh.io import curdoc
# Sample data
x = list(range(10))
y1 = [i**2 for i in x]
y2 = [i**1.5 for i in x]
source1 = ColumnDataSource(data=dict(x=x, y=y1))
source2 = ColumnDataSource(data=dict(x=x, y=y2))
fig1 = figure(title="Figure 1", width=400, height=400)
fig1.line('x', 'y', source=source1, line_width=2)
fig2 = figure(title="Figure 2", width=400, height=400)
fig2.line('x', 'y', source=source2, line_width=2)
# Initialize with synchronized x-range
fig1.x_range = DataRange1d()
fig2.x_range = fig1.x_range
sync_checkbox = CheckboxGroup(labels=["Synchronize x-axes"], active=[0])
def toggle_sync(attr, old, new):
if sync_checkbox.active:
# Synchronize x-axis
common_x_range = fig1.x_range
fig2.x_range = common_x_range
else:
# Unsynchronize x-axis
fig1.x_range = DataRange1d()
fig2.x_range = DataRange1d()
sync_checkbox.on_change('active', toggle_sync)
layout = column(sync_checkbox, fig1, fig2)
curdoc().add_root(layout)