Plotly Express Timeline / Gantt range_y

Iโ€™m attempting to apply a custom zoom to a gantt chart iโ€™ve created with plotly express, using the template and docs here:

My plot is fairly simple:

fig = px.timeline(df,x_start='start_date',x_end='end_date',y='milestone_name',color='milestone_type',range_x=[dt.now().date()-time_delta(days=3),dt.now().date()+time_delta(days=3)])
fig.update_traces(hovertemplate='Task: %{y}<br>Start: %{base|%m-%d-%Y}<br>End: %{x|%m-%d-%Y}')
fig.add_vline(x=dt.now().date(), line_width=3, line_color='blue')
fig.update_layout(yaxis=dict(title='Milestone',side='left'),xaxis=dict(title='Date'),showlegend=False)
fig.update_yaxes(autorange='reversed')

I can apply a custom range_x without issue using dates. But I canโ€™t figure out what is required for a custom range_y.

Iโ€™ve tried:

  • The two applicable milestone_names
  • The indexes of the two milestone_names
  • Two numbers in the range [0,1]
  • Two numbers in the range [0,100]

None of these seem to effect the y range zoom. Is it possible to apply a custom y range zoom to a px timeline?

Thanks in advance!

Replying to my own post as i finally figured it out. It seems you canโ€™t set the y range if you use:

fig.update_yaxes(autorange='reversed')

Instead you can reverse the axis and manually set the range by using:

fig.update_yaxes(range=[high_index,low_index])

Where high_index and low_index are the indexes of the timeline events, but listed from high to low to invert the y axis.