Hi @marekKnows.com,
I have no experience with plotly.js, but I succeeded with plotly.py to animate both a timeseries and a vertical line
at the actual date. I transformed the Python code to a low level one, to be as close as possible to plotly.js.
The trick is to reference the vertical line to the same xaxis as the timeseries, but to a secondary yaxis2 (placed at right side of the plot window and set invisible).
This is the animation https://plotly.com/~empet/15621/#/, and this the corresponding code:
import numpy as np
from datetime import datetime
dates = [datetime(2020, 1, k) for k in range(1, 32)]+ \
[datetime(2020, 2, k) for k in range(1, 30)]
d = {'date': dates,
'y':10+8*np.random.rand(60)}
ymin, ymax = d['y'].min(), d['y'].max()
trace0 = {'type': 'scatter',
'x': [d['date'][0]],
'y': [d['y'][0]],
'mode':'lines',
'line': {'color': 'blue'},
'yaxis': 'y'}
trace1 = {'x': [d['date'][0], d['date'][0]],
'y': [0, 1],
'mode': 'lines',
'line': {'color': 'red', 'width': 2},
'showlegend': False,
'xaxis': 'x',
'yaxis': 'y2'}
layout = {'height': 450,
'updatemenus': [{'buttons': [{'args': [None,
{'frame': {'duration': 50,
'redraw': False},
'transition': {'duration': 0},
'fromcurrent': True,
'mode': 'immediate'}],
'label': 'Play',
'method': 'animate'}],
'showactive': False,
'type': 'buttons',
'x': -0.1,
'xanchor': 'right',
'y': 1.05,
'yanchor': 'top'}],
'width': 800,
'xaxis': {'anchor': 'y',
'domain': [0.0, 0.94],
'range': [datetime(2020, 1, 1), datetime(2020, 2, 29)]},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'range': [ymin, ymax]},
'yaxis2': {'anchor': 'x',
'fixedrange': True,
'overlaying': 'y',
'range': [0, 1],
'side': 'right',
'visible': False}#THE seondary yaxis is invisible
}
n_frames =60
frames = []
for k in range(1, n_frames):
frames.append({'data': [{'type': 'scatter',
'x': d['date'][:k+1],
'y': d['y'][:k+1]},
{'type': 'scatter',
'x': [d['date'][k], d['date'][k]]}],
'traces':[0,1]})
fig ={'data': [trace0, trace1],
'layout': layout,
'frames': frames}