How to slow down animation in plotly express

Hi everyone,

I am desperately trying to slow down p. express animation speed,

Is there a way to achive that in figure.layout.update menu?

any help would be appreciated

Yes you can change the duration of the transition in the layout as follows

fig.update_layout(transition = {'duration': 1000})

See for example https://plot.ly/python/animations/#using-a-slider-and-buttons

Thank you very much for answering.

But unfortunately, I can’t get the result.
Let me share my codes with you.
I could’nt slow animation even with great numbers with transiton like ten thousand :frowning:

fig=px.scatter_geo(terör.sort_values(by='Year'), locations="Code", scope='asia', color="Unnamed: 2", hover_name="Unnamed: 2",  animation_frame="Year", text="Unnamed: 2",         
               size='Terrorism fatalities (GTD, 2018) (deaths)',             
             color_discrete_map=renk,template='plotly')

fig.update_traces(textposition='middle center',marker={'symbol':"circle-x"}, textfont={'color':'black','family':'Helvetica','size':17},mode="text+markers")

fig.layout.update( title_text="Asya'da Can Kaybıyla Sonuçlanan Terör Faaliyetleri (1970-2017)",title_font_size=30, showlegend=False,  transition= {'duration':8000 })

pio.show(fig)

Oh no, you’re right, other parameters need to be updated for example in the updatemenus. You can take a look at the examples in https://plot.ly/python/animations/ but I’m afraid it’s a bit advanced to do this…

1 Like

For example the code below has the right frame duration (4s) but I can’t get this working with px

import plotly.graph_objects as go

fig = go.Figure(
    data=[go.Scatter(x=[0, 1], y=[0, 1])],
    layout=go.Layout(
        xaxis=dict(range=[0, 5], autorange=False),
        yaxis=dict(range=[0, 5], autorange=False),
        title="Start Title",
        updatemenus=[dict(
            type="buttons",
            buttons=[dict(label="Play",
                          method="animate",
                          args=[None, {"frame": {"duration": 4000, "redraw": False},}])])]
    ),
    frames=[go.Frame(data=[go.Scatter(x=[1, 2], y=[1, 2])]),
            go.Frame(data=[go.Scatter(x=[1, 4], y=[1, 4])]),
            go.Frame(data=[go.Scatter(x=[3, 4], y=[3, 4])],
                     layout=go.Layout(title_text="End Title"))]
)
fig.update_layout(transition_duration=3000)
fig.show()
1 Like

This works for me with a px figure… you have to reach pretty deep into the configuration of the “play” button :slight_smile:

fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 2000
3 Likes

wuhuuu, you are hero, thank you so much, it work like a dream.

actually you both (@Emmanuelle and @nicolaskruchten) are my hero, your helps are appreciated a lot.:smiley::smiley:

greetings from Turkey…

2 Likes