没有插值的 Plotly 动画

Plotly animation without interpolation

我正在使用 Python 的 plotly.express.line 制作动画。是否可以在不插值的情况下从一帧过渡到另一帧?我正在尝试使用 fig.update_layout(transition={'easing': bla_bla_bla}) 但做不到。

  • 已创建一条动画线来演示
  • fig.layout.updatemenus[0].buttons[0].args[1]["transition"]["duration"] = 0表示播放按钮在帧间跳转,帧间无过渡
  • easing在这个动画中已经设置为linear
import numpy as np
import pandas as pd
import plotly.express as px

df = pd.DataFrame(
    {
        "x": np.tile(np.linspace(0, 19, 20), 10),
        "y": np.random.uniform(1, 5, 200),
        "frame": np.repeat(np.linspace(0, 9, 10), 20),
    }
)
fig = px.line(df, x="x", y="y", animation_frame="frame")
fig.layout.updatemenus[0].buttons[0].args[1]["transition"]["duration"] = 0
fig