âśŠđźŹż Black Lives Matter. Please consider donating to Black Girls Code today.
đź§¬ Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

# Perpetuate frame transition without increasing frames

Hi there,

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?

Thanks!

@tbillah

Define frames as follows:

``````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 {'color':'blue'}
)],
name=f'fr{i}') for i in range(20)]

)
``````

Transition duration can be modified in the `layout.updatemenus` and `layout.sliders`.

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)`?

Sorry, I actually meant continuing animation. I used the phrase continuing â€śtransitionâ€ť before, which might be misleading.

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.

1 Like