如何在Plotly中为热图制作动画 [英] How to animate a heatmap in Plotly

查看:89
本文介绍了如何在Plotly中为热图制作动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

我发现我要做的事情的问题-我需要指定'type':'heatmap'

  frames = [{'数据': [{'z':plane_wave(angle,phase),'类型':'热图'}]}用于np.linspace(0,0.1,30)中的相位] 

但是,jupyter笔记本现在出现此错误

IOPub数据速率超出.笔记本服务器将暂时停止将输出发送到客户端,以避免崩溃.要更改此限制,请设置config变量--NotebookApp.iopub_data_rate_limit.

我遵循了此处可停止此错误.但是,这非常不方便.而且,每一帧之间的步距是明显的间隙(即,帧速率低).我想知道是否有更好的动画热图方法

The Plotly documentation on heatmap animation is pretty difficult to understand. Could someone explain how to animate a heatmap?


Here is my specific example.

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)

I get

PlotlyDictKeyError: 'z' is not allowed in 'scatter'
Path To Error: ['frames'][0]['data'][0]['z']

Here's a picture of the heatmap I'm trying to animate:

解决方案

I figured out the problem with what I'd done - I needed to specify 'type': 'heatmap'

frames = [
    {
        'data': [{
            'z': plane_wave(angle, phase),
            'type': 'heatmap'
        }]
    } for phase in np.linspace(0, 0.1, 30)
]

However, the jupyter notebook now gives this error

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.

I followed the instructions here to stop this error. However, this is highly inconvenient. Also, the step between each frame takes is a noticeable gap (i.e., the frame rate is low). I wonder if there is a better method for animating a heatmap

这篇关于如何在Plotly中为热图制作动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆