添加滑块来绘制热图动画- python



我想为热图动画添加一个滑块。我有五个不同的数据帧(每个帧对应一个帧)。数据帧如下:

<表类> b tbody><<tr>530300b南200c南100d100444
  • 生成的与您所描述的内容相对应的数据帧列表
  • 键使用namego.Frames()构造函数和滑块当定义参数
import pandas as pd
import numpy as np
import plotly.graph_objects as go
dfs = [pd.DataFrame(index=list("abcd"), columns=list("ab"),
data=np.where(np.random.randint(1, 8, [4, 2]) == 1,
np.nan, np.random.randint(1, 500, [4, 2]),)
)
for i in range(10)]
# generate the frames. NB name
frames = [
go.Frame(data=go.Heatmap(z=df.values, x=df.columns, y=df.index), name=i)
for i, df in enumerate(dfs)
]
go.Figure(data=frames[0].data, frames=frames).update_layout(
updatemenus=[
{
"buttons": [{"args": [None, {"frame": {"duration": 500, "redraw": True}}],
"label": "Play", "method": "animate",},
{"args": [[None],{"frame": {"duration": 0, "redraw": False},
"mode": "immediate", "transition": {"duration": 0},},],
"label": "Pause", "method": "animate",},],
"type": "buttons",
}
],
# iterate over frames to generate steps... NB frame name...
sliders=[{"steps": [{"args": [[f.name],{"frame": {"duration": 0, "redraw": True},
"mode": "immediate",},],
"label": f.name, "method": "animate",}
for f in frames],}],
height=800,
yaxis={"title": 'callers'},
xaxis={"title": 'callees', "tickangle": 45, 'side': 'top'},
title_x=0.5,
)

最新更新