python - 如何在 Plotly 中制作热图动画

标签 python animation plotly heatmap

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']

这是我尝试制作动画的热图的图片:

Plane wave heatmap

最佳答案

我发现了我所做的问题 - 我需要指定 '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/

相关文章:

html - 在没有 Canvas 元素的情况下在 HTML 中裁剪 DIV

android - ViewPager 嵌套在 ViewPager 中

python - Plotly 的 treemap 和 sunburst 显示错误的大小

r - plotly R : bar chart with two axes

python - 解析带有 `pythons etree.iterparse()` 的巨大 xml 文件无法正常工作。代码有逻辑错误吗?

python - 在另一个Python脚本中调用Python脚本

animation - 如何从外部控制 Flutter 中的动画?

python - 如何将绘图与地理数据框几何一起使用

python - 抑制 python 警告

python - Opencv 转换为灰度无法正常工作