Multiple traces in a FigureWidget break callbacks
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 16時間 26分
- マージ済み PR(30日)
- 21
説明
Hello!
I am using
plotly 5.7.0
jupyterlab 3.3.2
ipywidgets 7.7.0
(these are the latest versions of each package)
I am not using Dash.
What I am trying to achieve is a simple FigureWidget with two scatter plots in it, each with a callback that prints the element the user has clicked on. However, the callbacks are fired incorrectly. The trace object given to the callback function is always the last added trace, not the one that the user clicked on.
Here is a minimal example which I adapted from the official documentation (https://plotly.com/python/click-events/#update-points-using-a-click-callback)
import plotly.graph_objects as go
from ipywidgets import Output
import numpy as np
import ipywidgets
np.random.seed(1)
scatter_1 = go.Scatter(x=np.random.rand(100), y=np.random.rand(100), mode='markers', hovertext="hello, I am scatter 1", marker={"symbol": "triangle-up", "size": 10, "color": "red"},)
scatter_2 = go.Scatter(x=np.random.rand(100), y=np.random.rand(100), mode='markers', hovertext="hello, I am scatter 2", marker={"symbol": "triangle-down", "size": 10, "color": "blue"},)
f = go.FigureWidget()
f.add_trace(scatter_1)
f.add_trace(scatter_2)
f.layout.hovermode = 'closest'
f
This correctly renders the figure:

Then, I add a callback, one to each trace, by manipulating f.data:
o = ipywidgets.Output()
@o.capture(clear_output=True)
def callback(trace, points, selector):
print(trace)
print(points)
print(selector)
f.data[0].on_click(callback)
f.data[1].on_click(callback)
o
Clicking a blue triangle works, it correctly shows the clicked trace and point:

Clicking a red triangle yields wrong output. The point object is somehow empty, and the trace object is wrong (trace 1 even though trace 0 was clicked):

コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
plotly 5.7.0、JupyterLab 3.3.2、ipywidgets 7.7.0 を使用して、2 つのトレースを持つ FigureWidget の例を再現します。まず f.data[i].on_click(callback) の処理を追跡し、最初のトレースと最後のトレースのコールバックを比較します。どちらのトレースをクリックしても、クリックされたトレースとポイントが正しく報告されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- jupyter-notebook, python
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100