In the example below, I am changing color of the points between red and blue. The question is, how do I perputate the frame transitions without making the number of frames infinity?
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Scatter(x=[1,2,3,4], y=[1,2,3,4],mode='markers')],
frames=[go.Frame(data=[go.Scatter(x=[1, 2, 3, 4], y=[1, 2, 3, 4],marker={'color':'red'})]) if i%2 else go.
Frame(data=[go.Scatter(x=[1, 2, 3, 4], y=[1, 2, 3, 4],marker={'color':'blue'})]) for i in range(20)]
)
fig.show()
Another related question, how do I modify transition time between frames?
Hi @empet, sorry about the delay. I think you simplified my frames definition only without giving a way for continuing animation. The animation still stops after 10 beats. My first question was, can I continue the animation in a never ending fashion without writing something like range(inf)?
Hi @tbillah,
I donโt think you can create a Plotly animation which never stops, because first you have to define the list of frames, then pass them to go.Figure, and finally itโs plotly.js that starts it.
If you define an infinite loop to create the frames it never stops to pass them to fig:
frames =[]
k=0
while(True):
frames.extend([go.Frame(data=[go.Scatter(x=[1, 2, 3, 4],
y=[1, 2, 3, 4],
marker={'color':'red'} if i%2 else {'color':'blue'})],
name=f'fr{k+i}') for i in range(20) )
k+ = 20
I suppose that only plotly.js, not plotly.py, could replay the already defined n distinct frames, repeating them again and again, like in a gif file.
But so far Iโm not aware of such a possibility.