Update y axis domain when zoomed on x axis

Is it possible to have y axis domain updated to the range of the data, displayed after x axis zoom?

Ie, both axes update if zoomed on both directions:

but if zoomed only along x scale - the y scale doesn’t change (domain stays the same):

Does plotly allow automatic update of y axis in the 2nd example?


What kind of automatic are you looking for?

Are you looking for something like https://github.com/plotly/plotly.js/issues/272 ?

You could try setting autorange to true on the y axis once the event has fired off and update the layout.

I’m not sure if aspectratio is what I’m after. I need zooming in x-direction only:

…to result into this (note y axis range changed)

but isn’t autorange set to true by default? Single-Page Reference | JavaScript | Plotly

That seems to be the case when the plot is initially drawn. However, after the event occurs, I’m not sure if this changes. I would suggest consoling the plot layout after the event occurs to check.

Thank you for you input.
Logging layout on plotly_relayout still shows that autorange keeps ‘true’ value.

To achieve updating y axis range, I ended up listening to plotly_relayout event, use it’s eventdata (xaxis.range) to filter the data, and redraw the plot with filtered data.

Would you mind sharing the piece of code?

Following is a working example of the desired behavior, that is, to have the y axis range update as a different x axis range is selected.

It works as expected. The only remaining issue is that the range slider y axis changes and therefore does not display the traces in full (it is also always the case with log yaxis scale, as reported in Range slider doesn't display trace when y axis set to log scale)

1 Like

eagor, could you please share the code. thanks

Here’s a nice example of the y-axis updating on date zoom (zoom over to the left of x-axis)
Is there an issue for this on github?

1 Like