I’m currently plotting some timeseries where changes from e.g. week to week are interesting. I see there is a
rangeslider option which I’ve applied to the time-Axis and with
rangeselectors I added buttons to set the duration of the sliding window.
Now the problem I have is that when I move this sliding window, I cannot place it precisely at the e.g. starts of a week. An even better workflow would be to have a button
+7 days which then moves the window automatically by the specified duration.
One quick example (don’t be confused I used different data thus the period of time is longer):
import plotly.graph_objects as go import plotly.express as px from plotly.subplots import make_subplots df = px.data.gapminder() df = df.sort_values(by=['year']) df = df[df["country"] == "China"] print(df) # make figure fig = make_subplots() fig.update_xaxes(title="Year") fig.update_yaxes(title="GDP per Capita") fig.update_layout(hovermode="closest") dataset_cont = df[df["continent"] == "Asia"] fig.add_trace( go.Scatter( y=dataset_cont["gdpPercap"], x=dataset_cont["year"], mode="lines", text=dataset_cont["country"], ) ) fig.update_layout( xaxis=dict( rangeselector=dict( buttons=list([ dict(count=1, label="1y", step="year", stepmode="backward"), dict(count=5, label="5y", step="year", stepmode="backward"), dict(count=10, label="10y", step="year", stepmode="backward"), dict(step="all") ]) ), rangeslider=dict( visible=True ), type="date" ) ) fig.show()
Gives this plot:
Now after clicking the imaginary button, the following should have happened:
Does anyone know how to do this?
As I only want to somehow step through the period of times, I’d be completely fine with some sort of an animation. I this case I already have a slider with is somehow “rasterized” (no free selection of starting points). Still I’d need a button which does
step to next frame (didn’t find how to do this up to now). This isn’t an optimal solution (using
rangeslider is much nicer) but would suffice as well.
I already discovered this (unanswered) community.plotly question and this (unanswered) stackoverflow question but sadly no answers up to now (and nothing on “rasterizing”/stepping through the rangeslider which is the much nicer solution though)