plotly / plotly/plotly.py

FigureWidget update issues after single bin histogram.

Đang mở
#4,235 0 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ả

Running into an (admittedly quite edgy) issue updating a plotly graph_object Histogram in a FigureWidget.

The issue only seems to arise when using barmode='overlay' and seems to result from updating .data[0].x to a degenerative
(single bin) array (i.e. all elements equal).

Running in Jupyterlab the issue can be reproduced by:

import plotly.graph_objects as go
import numpy as np
hist_wgt = go.FigureWidget([go.Histogram(x=np.random.random(200), histnorm='probability', opacity=0.7)],
                          layout=dict(barmode='overlay'))
display(hist_wgt)

which produces a nicely binned histogram e.g.
histo0
and

print("xrange:", hist_wgt.layout.xaxis.range)
print("nbinsx:", hist_wgt.data[0].nbinsx)
print("yrange:",hist_wgt.layout.yaxis.range)
print("start:", hist_wgt.data[0].xbins.start)
print("end:", hist_wgt.data[0].xbins.end)
print("size:", hist_wgt.data[0].xbins.size)

xrange: (6.938893903907228e-17, 0.9999999999999999)
nbinsx: 0
yrange: (0, 0.1736842105263158)
start: 0
end: 1
size: 0.1

However, if we update hist_wgt.data[0].x with a (terrible) uniform array:

hist_wgt.data[0].x = np.ones(200)

the histogram becomes a single bin (as expected):
histo1
and the layout and bin info:

xrange: (0.5, 1.5)
nbinsx: 0
yrange: (0, 1.0526315789473684)
start: 0.5
end: 1.5
size: 1

The issue now happens when we try to update hist_wgt.data[0].x, but with with a more sensible array:

hist_wgt.data[0].x = np.random.random(200) * 1e6

it seems the widget layout is not re-evaluated or updated for this new x:
histo2
although nbinsx does get set to None (unsure if this is significant):

xrange: (0.5, 1.5)
nbinsx: None
yrange: (0, 1.0526315789473684)
start: 0.5
end: 1.5
size: 1

My guess is that the ambiguous nature of bin-width where the data range is 0 means that something is being set for the widget layout for that special case -- and then this setting overrides any later auto-range operations?

I am happy to admit that trying to plot a single bin histogram is slightly pointless but I want the histogram to be updatable for user selected variables, some of which could could collapse to a single value. I have tried to find an option to force the layout update through but haven't stumble upon the right combination of calls.

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

Bắt đầu với việc tái hiện FigureWidget và go.Histogram trong JupyterLab, trước tiên xác nhận chuỗi cập nhật từ dữ liệu đa dạng thành một mảng một bin rồi quay lại. Theo dõi cách thay đổi FigureWidget.data[0].x cập nhật siêu dữ liệu bin và phạm vi trục của biểu đồ histogram; hoàn thành khi layout và thông tin bin được tính toán lại cho dữ liệu mới thay vì giữ nguyên các giá trị một bin.

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, numpy, 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
35/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.