Plotly documentation on heatmap animation是很难理解的。有人可以解释一下如何制作热图动画吗?
<小时/>这是我的具体示例。
import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
x = np.linspace(0, 1, 200)
y = np.linspace(0, 1, 200)
xx, yy = np.meshgrid(x, y)
def plane_wave(phase):
return np.sin(8*np.pi * (xx - phase))
zz = plane_wave(0)
trace = go.Heatmap(
x=x,
y=y,
z=zz,
)
# This doesn't work:
frames = [
{'data': [{'z': plane_wave(phase)}]} for phase in np.linspace(0, 2*np.pi)
]
data=[trace]
fig = go.Figure(data=data, frames=frames)
iplot(fig)
我明白了
PlotlyDictKeyError: 'z' is not allowed in 'scatter'
Path To Error: ['frames'][0]['data'][0]['z']
这是我尝试制作动画的热图的图片:
最佳答案
我发现了我所做的问题 - 我需要指定 'type': 'heatmap'
frames = [
{
'data': [{
'z': plane_wave(angle, phase),
'type': 'heatmap'
}]
} for phase in np.linspace(0, 0.1, 30)
]
但是,jupyter笔记本现在给出了这个错误
IOPub data rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable --NotebookApp.iopub_data_rate_limit.
我按照指示 here 进行操作来停止这个错误。然而,这非常不方便。此外,每帧之间的步长有明显的差距(即帧速率较低)。我想知道是否有更好的方法来动画热图
关于python - 如何在 Plotly 中制作热图动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45712242/