plotly / plotly/plotly.py

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

オープン
#5,256 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug P2
主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、plotly.py に用意されている最小限の Python 例を実行し、go.Contour のみの場合のアニメーションと、追加の go.Scatter トレースを含む場合のアニメーションを比較します。輪郭データに対して Figure と Frame が使用するアニメーション/レンダリング経路を追跡します。複数のトレースが存在する場合でもすべてのフレームで輪郭が正しくレンダリングされ、単一トレースの場合を退行させないことが完了条件です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。