简体   繁体   中英

How can I turn on autoplay for a Plotly express animation? (Python)

there is no documentation on this at all and so I am just putting this out there as these questions on Plotly forums are never answered (although there being a lot of views for these questions, indicating lots of people encounter this problem).

Would appreciate any ideas.

According to Plotly Express documentation , by default, a plot in HTML format will autoplay. So I guess the solution is to save your interactive plot as HTML and then open this saved file.

In Python,

import plotly.express as px
import pandas as pd
import webbrowser

df = pd.DataFrame(dict(
    x=[1, 3, 2, 4],
    y=[1, 2, 3, 4],
    t=[2000, 2001, 2002, 2003]
))
fig = px.scatter(df, x="x", y="y",
                 animation_frame="t",
                 size='x',
                 range_x=[0, 6], range_y=[0, 6]
                 )
# instead of using fig.show() use this:
fig.write_html("test.html")
url = 'test.html'
webbrowser.open(url, new=2) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM