Black Lives Matter. Please consider donating to Black Girls Code today.

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?

http://codepen.io/plotly/pen/WvPgPP

1 Like

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? https://plot.ly/javascript/reference/#layout-scene-yaxis-autorange

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.

SOLUTION.
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)
https://www.google.co.uk/publicdata/explore?ds=d5bncppjof8f9_&met_y=ny_gdp_pcap_cd&hl=en&dl=en#!ctype=l&strail=false&bcs=d&nselm=h&met_y=ny_gdp_pcap_cd&scale_y=lin&ind_y=false&rdim=region&idim=country:PAN:GBR:NIC:AUS:USA&ifdim=region&tdim=true&tstart=-300934800000&tend=1466290800000&hl=en_US&dl=en&ind=false
Is there an issue for this on github?

1 Like