go.Scatter ignores the masked array elements in numpy masked arrays
Chưa có ai nhận issue này.
- 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ả
Bug summary
Plotting a numpy masked array, px.scatter plots the non-masked array elements and limits the axis accordingly, while go.Scatter also displays the masked data and does also include the masked elements for the axis limits. The behavior from go.Scatter is unexpected in this regard and ignoring the mask defeats the purpose of masked arrays.
Minimal viable code
import numpy.ma as ma
import plotly.express as px
import plotly.graph_objects as go
# Create timestamps
time_unmasked = [1,2,3,4,5,6,7]
# Create a masked array with three masked variables, one datapoint far from others
data_masked = ma.array([15,14,50,15,15,15,16], mask=[0,0,1,1,1,0,0])
fig_px = px.scatter(x=time_unmasked, y=data_masked, title='Plotly Express')
fig_px.show()
fig_go = go.Figure(layout=go.Layout(
title=go.layout.Title(text="Plotly Graph Objects")))
fig_go.add_trace(go.Scatter(x=time_unmasked, y=data_masked))
fig_go.show()
Thanks to @Benblob688 for his code example in the issue mentioned below.
Actual outcome
Using plotly.graph_objects, the masked data entries at position 2,3,4 with the values 50,15,15 are drawn into the plot and the axis limits are set accordingly.
Expected outcome
Using plotly.express, the masked data entries are not shown and the axis limits are set accordingly to only include non-masked entries in the array.
Additional information
Matplotlib had a similar issue here, where the code has been adapted from to display this issue here. It seems that the usage of np.column_stack caused an issue there, that function has since been replaced with np.ma.column_stack.
Operating system
Ubuntu 20.04
Plotly Version
5.14.1
Numpy Version
1.24.1
Python version
3.11.3
Installation
conda
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với ví dụ mã tối thiểu và so sánh px.scatter với go.Scatter khi được truyền vào mảng NumPy đã che. Theo dõi cách mỗi điểm vào xử lý các phần tử đã che và các giới hạn trục, sau đó thêm hoặc cập nhật độ bao phủ cho ví dụ đã báo cáo. Công việc được hoàn tất khi go.Scatter không còn vẽ các giá trị đã che hoặc đưa chúng vào các giới hạn trụ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ệ
- numpy, python
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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