【发布时间】:2021-10-10 11:51:39
【问题描述】:
我想为热图动画添加一个滑块。我有五个不同的数据帧(每个数据帧一帧)。数据框如下:
| a | b | |
|---|---|---|
| a | 530 | 300 |
| b | NaN | 200 |
| c | NaN | 100 |
| d | 100 | 444 |
每一帧实际上都是时间数据。为简单起见,我使用了计数。到目前为止,这是我的代码。动画有效,播放和暂停按钮也有效。我能够创建一个滑块,但它不起作用。我错过了什么吗?有人可以帮忙吗?
# Convert the dictionaries to dataframes
df = {}
frames = 0
for i in caller_callees:
df[i] = pd.DataFrame(dict[i], dtype=int).T
frames += 1
fig = go.Figure(
data=[go.Heatmap(z=df[0].values, x=df[0].columns, y=df[0].index)],
layout=go.Layout(
# autosize=True,
height=800,
yaxis={"title": 'callers'},
xaxis={"title": 'callees', "tickangle": 45, 'side': 'top'},
title="Frame 0",
title_x=0.5,
updatemenus=[
dict(
type="buttons",
buttons=[dict(label="Play",
method="animate",
args=[None]
),
dict(label="Pause",
method="animate",
args=[None,
{"frame": {"duration": 0, "redraw": False},
"mode": "immediate",
"transition": {"duration": 0}}],
)
],
),
],
),
frames=[go.Frame(data=[go.Heatmap(z=df[i])],
layout=go.Layout(title_text=f"Frame {i}"))
for i in range(0, frames)]
)
# finally create the slider
fig.update_layout(
sliders=[{"steps": [{"args": [
[f],
{"frame": {"duration": 0, "redraw": False},
"mode": "immediate",
"transition": {"duration": 300}
},
],
"label": f, "method": "animate", }
for f in range(0, frames)],
}],
)
【问题讨论】:
标签: python plotly plotly.graph-objects