plotly / plotly/plotly.py

go.Contour doesn't render correctly in animation frames when multiple traces are present

未关闭
#5,256 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

I'm encountering an issue with plotly.graph_objects.Figure animations. When using go.Contour inside go.Frame along with additional traces such as go.Scatter, the contour plot no longer renders correctly during animation. However, if I only include the go.Contour trace by itself in each frame, it animates perfectly.
Here's a minimal reproducible example:

import plotly.io as pio
pio.renderers.default = 'browser'
import plotly.graph_objects as go
import numpy as np

z_base = np.array([
    [10, 10.625, 12.5, 15.625, 20],
    [5.625, 6.25, 8.125, 11.25, 15.625],
    [2.5, 3.125, 5., 8.125, 12.5],
    [0.625, 1.25, 3.125, 6.25, 10.625],
    [0, 0.625, 2.5, 5.625, 10]
])

lk_x=[0,0,1,1,0]
lk_y=[0,1,1,0,0]

data_line = go.Scatter(x=lk_x, y=lk_y, mode='lines', fill='toself', fillcolor='rgba(60, 53, 48, 0.5)', line_color='black', showlegend=False)

scales = np.linspace(0.2, 1.0, 10)
frames = []
for i, s in enumerate(scales):
    z_scaled = z_base * s
    frames.append(go.Frame(
        data=[
            go.Contour(
                z=z_scaled,
                colorbar=dict(
                    thickness=25,
                    thicknessmode='pixels',
                    len=0.6,
                    lenmode='fraction',
                    outlinewidth=0
                )
                ,zorder=2
            ),
            go.Scatter(
                x=[0, 1, 2, 3, 4],
                y=[0, 1, 1.5, 2, 3], 
                mode='lines',
                line=dict(color='black', width=2),
                showlegend=False,
                zorder=0
            ),
            data_line
        ],
        name=f"scale_{i}"
    ))


fig = go.Figure(
    data=frames[0].data,
    frames=frames
)

fig.update_layout(
    title="Contour",
    updatemenus=[{
        "buttons": [
            {"label": "play", "method": "animate", "args": [None, {"frame": {"duration": 500}, "fromcurrent": True}]},
            {"label": "pause", "method": "animate", "args": [[None], {"mode": "immediate", "frame": {"duration": 0}}]}
        ],
        "type": "buttons",
        "showactive": True,
        "x": 0.1,
        "y": -0.1
    }],
    sliders=[{
        "steps": [{"args": [[f.name]], "label": f"Step {i+1}", "method": "animate"} for i, f in enumerate(frames)],
        "x": 0.1,
        "len": 0.9
    }],
    width=500,
    height=500
)

fig.show()

only include the go.Contour trace:

Image

with additional traces:

Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行 plotly.py 中提供的最小 Python 示例,并比较仅使用 go.Contour 的动画与包含额外 go.Scatter 轨迹的动画。跟踪 Figure 和 Frame 用于等高线数据的动画/渲染路径;完成的标准是:存在多个轨迹时,等高线在所有帧中都能正确渲染,同时不影响单轨迹的情况。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。