Plotly with python:如何使用框架和滑块绘制两个热图?

问题描述 投票:0回答:0

我需要帮助在 python 中创建一个复合动画图表。

这种图表的静态版本是这样的 Double static chart,这是用python中的以下代码完成的:

def double_hm_plot(vec1, vec2):
    fig = plotly.subplots.make_subplots(rows=1, cols=2, shared_yaxes=True, shared_xaxes=True)
    fig.add_trace(go.Heatmap(z=vec1.T, coloraxis='coloraxis1'), row=1, col=1)
    fig.add_trace(go.Heatmap(z=vec2.T, coloraxis='coloraxis2'), row=1, col=2)
    fig.update_layout(
        legend=dict(x=0.5, xanchor='center', y=1, yanchor='bottom', orientation='h'),
        coloraxis1=dict(colorscale='jet', colorbar_x=-0.20, colorbar_thickness=10),
        coloraxis2=dict(colorscale='jet', colorbar_x=1.00, colorbar_thickness=10),
        width=600, height=700)
    fig.show()

代码采用两个包含空值的二维 numpy 数组(数组的数组,而不是矩阵)并将它们绘制为热图。比较简单,coloraxis lines只是为了正确放置colorscales bars。

我能够制作我需要的动态/动画图表的唯一一半,只有一个热图显示在“double_hm_plot”中,使用如下滑块:(结果:Single dynamic chart

structure = files['gas'][1:]
min_scale, max_scale = np.min(np.min(np.min(structure))), np.max(np.max(np.max(structure)))
frames = [go.Frame(data=go.Heatmap(z=frame.T, colorscale='Turbo', 
                                   zauto=False,
                                   zmin=min_scale, zmax=max_scale
                                   ), name=i) for i, frame in enumerate(structure)]

go.Figure(data=frames[0].data, frames=frames).update_layout(
    sliders=[{"steps": [{"args":[[f.name],{"frame": {"duration": 0, "redraw": True}, "mode": "immediate",},],
                         "label":f.name, "method": "animate",}
                        for f in frames],}],
    height=600, width=300,
    yaxis={"title": 'y [m/10]'},
    xaxis={"title": 'r [m/10]', 'side': 'top'},
    title_x=0.5,
)

第二个代码使用多一维的时间,并以大致相同的方式绘制。

我怎么能用这个滑块使用两个并排的图(比如在“double_hm_plot”中)?

我已经尝试了很多东西,但似乎没有任何效果。诸如:用多个“go.heatmap”对象组合帧,在图中使用多个帧等

关于文档,我也没有找到太多帮助。

有什么帮助吗,这甚至可能吗?

文件示例测试:https://drive.google.com/drive/folders/1Vpt_HfJxCsYoghvwerzfHEpJAq6MJHE1?usp=share_link

python animation plotly slider heatmap
© www.soinside.com 2019 - 2024. All rights reserved.