plotly / plotly/plotly.py

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

Đang mở
#3,976 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P3
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

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'

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện ví dụ px.scatter và FigureWidget được cung cấp trong một notebook Jupyter bằng Python 3.8.8 và Plotly 5.11.0, so sánh việc chọn có và không có color="species". Theo dõi các callback chọn trên fig.data và xác minh rằng point_inds chứa các hàng được chọn cho mỗi trace có màu; hoàn tất khi việc chọn bằng lasso và box báo cáo các chỉ mục mong đợi thay vì một mảng rỗng hoặc không chính xác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
jupyter-notebook, python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.