Is it possible to catch plot range when user zooms?

Hi!

I am working on electricity consumption plot and I stumbled across a problem. I have hourly data from consumption and I want to be able to offer few different sums with the plot. The most important would be hourly data from 1-3 days but when zoomed farther away hourly data is quite hard to read for the user so if the x-axis range is 4 or more weeks maybe hourly data summed as daily would be more suitable and etc.

The data handling it self is already done but what I am asking that is there a way to catch current axis range so I can change the data when the range gets wider/narrower?

Alternatively if the range selector buttons can be used for this that might be a option.

I attached a picture just to give initial idea of the plot.

Hi,
what you are looking for is the relayoutData attribute of dcc.Graph. See also the 4th part of Dash tutorial.

You will need to implement a callback updating the figure. Be careful as it could be tricky to go back to the original full scale plot. You may want to add a “reset” button.
Good luck!

2 Likes

Thank you!

This was the thing I was looking for. I now implemented it and it seems to work fine.