Cumulative plots that rebase when zoomed

I would like to know if there is some way of plotting cumulative line graphs (for example, cumulative profits on the y-axis and time on the x-axis), such that upon zooming into a different range on the x-axis, the y values are updated to accumulate starting from the left of the x-axis range. Thanks!

Here’s an example of how to plot different data set depending on the visible range:

I hope this will help you get started.

Thanks, that helps. Since I am generating these graphs in python, is there a way to attach a python function to the relayout event instead?

Not at the moment unfortunately.

I have tried this recipe but I have a time series data set, where x are dates and y the values. When i zoom into the plot and recalculate the cumulative distribution between xRange[0] and xRange[1] the plot clears as these dates are not in the x array but somehow created by plotly when creating the plot. Is there a workaround for this? Thanks.