2 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
非常感謝兄弟的回答;有用。
我構(gòu)建了一個(gè)與您的解決方案類似但有一些差異的解決方案:
import plotly.express as px
import plotly.graph_objects as go
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
last_frame_num = len(fig.frames) -1
fig.layout['sliders'][0]['active'] = last_frame_num
fig = go.Figure(data=fig['frames'][-1]['data'], frames=fig['frames'], layout=fig.layout)
fig
不管怎樣,我非常感謝您的關(guān)注/支持,在實(shí)施某些事情時(shí)有更多的選擇真是太好了!
非常感謝; 最好的問(wèn)候,萊昂納多

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
問(wèn)題是fig.data你有第一幀。我找到了生成新圖形的解決方法。
import plotly.express as px
import plotly.graph_objects as go
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
# New figure
fig2 = go.Figure()
# add last frame traces to fig2
for tr in fig.frames[-1].data:
fig2.add_trace(tr)
# copy the layout
fig2.layout = fig.layout
# copy the frames
fig2.frames = fig.frames
# set last frame as the active one
fig2.layout['sliders'][0]['active'] = len(fig.frames) - 1
fig2
添加回答
舉報(bào)