go.Scatter ignores the masked array elements in numpy masked arrays
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从最小代码示例开始,在传入带掩码的 NumPy 数组时比较 px.scatter 和 go.Scatter。跟踪每个入口点如何处理带掩码的元素和坐标轴范围,然后为报告的示例添加或更新覆盖测试。完成的标准是 go.Scatter 不再绘制带掩码的值,也不再将其纳入坐标轴范围。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- numpy, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100