Dash/plotly time series visualization, how to keep zoom level consistent on parts with no data

Viewed 146

I've been dealing with this issue for sometime now. I have a typical time series over some measure. My code and logic is pretty complex to display it here, I'll try to summarize it instead. My chart by default is organized in DAYS, but if I zoom in, using relayoutdata, I re-organize my dataframe by HOURS, zooming further, by Minutes, and the smallest gradation is by Seconds: Full - zoomed out view The problem appears when I try to zoom on time areas that don't have any data to display, or have a single record. If I have at least two points on a chart, everything works as expected: Two point - still ok

but if I nudge the zoom by tiny bit so to exclude one of the two remaining columns, the whole visualization rescales to this following chart.

This is the problem One large column chart

This is the desired output: Ideally desired output

On zoom, I re-filter my pd.DataFrame, and as with the last example, my df only has one record. So, the Plotly is driven by that one data point, and what I would like instead is to display the data and force it to use: {'xaxis.range0': '2021-10-08 12:17:44', 'xaxis.range1': '2021-10-17 00:20:39'}

My thought process was to keep track of how many data points I have in the dataframe, and if the count is below a certain threshold, to artificially fill df with 0s. But I believe this is patchy solution, and maybe there's a more elegant way to keep the timeline consistent.

Any help will be greatly appreciated.

0 Answers
Related