plotly / plotly/plotly.py

Box/Lasso selection giving wrong indices in point_inds for px.scatter

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

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

bug P3
主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
21

説明

Hi,
I am implementing lasso/box selection in a scatterplot. I am using a callback function that returns me the indices of data selected by the user. The code works fine and returns me the correct indices when I applied a continuous or no label to the points. However, when I color the points using a discrete label I get incorrect indices or empty array.

Sample code to run is given below.

import plotly.express as px
import plotly.graph_objects as go
from plotly.graph_objs import *
from IPython.display import display

df = px.data.iris()
selected = []
def filter_(trace, points, state):
    global selected
    print(points)
    selected = points.point_inds

layout = Layout(
    paper_bgcolor='rgba(0,0,0,0)',
    plot_bgcolor='rgba(0,0,0,0)',
    width=1000,
    height=600,

)

fig = px.scatter(
    df,
    x='sepal_length',
    y='sepal_width',
    color="species",

)

fig.layout=layout
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)
fig = go.FigureWidget(fig.data, fig.layout)
fig.layout.dragmode = 'lasso'
fig.data[0].on_selection(filter_)

display(fig)
dh = display(display_id=True)

On making a lasso/box selection this is the output thrown. As you can see point_inds is empty.

Points(point_inds=[],
       xs=[],
       ys=[],
       trace_name='setosa',
       trace_index=0)

If you comment color="species" , the code works fine.

In the above code, I also applied on_selection on all objects of fig.data but still did not work.

for f in fig.data:
    f.on_selection(filter_)

Version info -

Python - '3.8.8'
Plotly - '5.11.0'

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Python 3.8.8 と Plotly 5.11.0 を使用して、提供された px.scatter と FigureWidget の例を Jupyter ノートブックで再現し、color="species" を指定した場合と指定しない場合で選択を比較します。fig.data の選択コールバックを追跡し、各色付き trace について point_inds に選択された行が含まれていることを確認します。lasso 選択と box 選択が、空または誤った配列ではなく期待されるインデックスを報告すれば完了です。

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

評価

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

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

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