# Perpetuate frame transition without increasing frames

**URL:** <https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315>\
**Category:** Dash Python\
**Created:** [May 12, 2020, 3:09pm UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315 "2020-05-12T15:09:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [May 12, 2020, 3:09pm UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315/1 "2020-05-12T15:09:23Z")

</div>

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?

```auto
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!

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [May 12, 2020, 4:59pm UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315/2 "2020-05-12T16:59:55Z")

</div>

@tbillah

Define frames as follows:

```auto
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`.

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [May 12, 2020, 9:03pm UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315/3 "2020-05-12T21:03:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [May 12, 2020, 9:21pm UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315/4 "2020-05-12T21:21:05Z")

</div>

Sorry, I actually meant continuing animation. I used the phrase continuing “transition” before, which might be misleading.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [May 13, 2020, 5:15am UTC](https://community.plotly.com/t/perpetuate-frame-transition-without-increasing-frames/39315/5 "2020-05-13T05:15:22Z")

</div>

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:

```auto
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.
