【问题标题】:How can I turn on autoplay for a Plotly express animation? (Python)如何为 Plotly express 动画打开自动播放? (Python)
【发布时间】:2022-06-18 16:15:49
【问题描述】:

根本没有这方面的文档,所以我只是把它放在那里,因为 Plotly 论坛上的这些问题从未得到解答(尽管对这些问题有很多看法,表明很多人遇到了这个问题)。

任何想法都将不胜感激。

【问题讨论】:

    标签: python plotly plotly-express


    【解决方案1】:

    根据Plotly Express documentation,默认情况下,HTML 格式的绘图将自动播放。所以我想解决方案是将您的交互式绘图保存为 HTML,然后打开这个保存的文件。

    在 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) 
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 2011-11-14
      • 2022-11-11
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 2021-05-11
      相关资源
      最近更新 更多