OK, I figured out how to limit the y coordinate:
import plotly.express as px
import numpy as np
import pandas as pd
# frames for animation
step = 21
frame = np.linspace(0 , 0.1, step)
# data
x = [1 for _ in range(step)]
y = np.asarray([0.1*i for i in range(step)])
# different velocities
faster = y * 2
slower = y / 2
# the slowest point defines the maximum y coordinate
max_y = slower.max()
# limit faster points to y_max
y = [i if i<=max_y else max_y for i in y]
faster = [i if i<=max_y else max_y for i in faster]
# create DataFrame
df = pd.DataFrame({'x':x,'y':y, 'slower':slower, 'faster':faster, 'frame':frame})
# create figure
fig = px.strip(
df,
x=x,
y=['y','slower', 'faster'],
animation_frame='frame',
range_x=[0.5, 1.5],
range_y=[0, max_y],
height=600,
width=600
)
fig.show()
creates:
