Box/Lasso selection giving wrong indices in point_inds for px.scatter
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 18.8k
- 分支
- 2.8k
- 平均合併
- 16 小時 26 分鐘
- 30 天內合併 PR
- 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'
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 Python 3.8.8 和 Plotly 5.11.0,在 Jupyter notebook 中重現提供的 px.scatter 和 FigureWidget 範例,比較有和沒有 color="species" 時的選取。追蹤 fig.data 上的選取回呼,並驗證每個著色 trace 的 point_inds 都包含選取的資料列;當 lasso 和 box 選取回報預期的索引,而不是空陣列或錯誤陣列時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- jupyter-notebook, python
- 領域
- data-visualization
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100