Autoscaling y axis on linked box zoom with dimension = width

I’m trying to create two linked plots where I can zoom in on either x-axis and have the corresponding y-axes automatically re-scale. As the data in the two plots is different, the range of y-axis values taken by each plot will be different and dependent upon the min and max of the data within the new selection.

I’ve tried many, many things but just can’t get it to work. A basic working setup of the problem is below:

from bokeh.plotting import figure, show
from bokeh.layouts import gridplot
from bokeh.models import BoxZoomTool, ColumnDataSource, DataRange1d
import pandas as pd
import random

def gen_df(points):
    df = pd.DataFrame()
    df['x'] = range(0, points)
    y1 = []
    y2 = []
    y1_now = 100
    y2_now = 100
    directions = ["UP", "DOWN", "HOLD"]

    for i in df['x']:
        step1 = random.choice(directions)
        step2 = random.choice(directions)    
        if step1 == "UP":
            y1_now += 1
        elif step1 == "DOWN":
            y1_now -= 1
        if step2 == "UP":
            y2_now += 1
        elif step2 == "DOWN":
            y2_now -= 1

    df['y1'] = y1
    df['y2'] = y2
    return df

my_source = ColumnDataSource(data=gen_df(1000))

p1 = figure(width=1000, height=300, y_range=DataRange1d(only_visible=True), tools=[BoxZoomTool(dimensions='width'), 'reset'])
p1.step(source=my_source, x='x', y='y1', color='#A6CEE3', mode='after')
p2 = figure(width=1000, height=300, x_range=p1.x_range, y_range=DataRange1d(only_visible=True),
p2.step(source=my_source, x='x', y='y2', color='#FB9A99', mode='after')
p2.x_range = p1.x_range
fig = gridplot([[p1], [p2]])

Windowed auto-ranging is still an open issue:

For now you would have to manually compute and set new y-range bounds based on the data that is currently visible.