px.line erratic and wrong for large x value ranges
未关闭
还没有人认领这个 Issue。
bug
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Problem
Plotting a straight line from ($-X$, 0) to ($+X$, 1) for various (large) $X$ within a much smaller window results in wrong and inconsistent behavior, as demonstrated in below minimum non-working examples (using a Jupyter notebook with plotly.js v2.27.0).
I doubt that this behavior can be explained by intrinsic rounding problems, since
>>> np.interp([-0.1,0.1],[-1e17,+1e17],[0,1])
array([0.5, 0.5])
>>> np.interp([-0.1,0.1],[-1e18,+1e18],[0,1])
array([0.5, 0.5])
Examples
Data frame
df = pd.DataFrame(dict(x=[-1e17,+1e17,-1e18,+1e18],
y=[0,1,0,1],
xlimit=['±1e17','±1e17','±1e18','±1e18']))
Very tight plotting range (symmetric 0.1)
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-.1,.1],
range_y=[0.4,0.6],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
Slightly wider plotting range (symmetric 0.3)
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-.3,.3],
range_y=[0.4,0.6],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
Another plotting range (symmetric 1)
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-1,1],
range_y=[0.4,0.6],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
Another even wider plotting range (symmetric 3)
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-3,3],
range_y=[0.4,0.6],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
Apparently wide enough plotting range (symmetric 3.2)
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-3.2,3.2],
range_y=[0.4,0.6],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
As far as my tests go, for any range_x that is wider than about ±3, the plotting is rendered correctly:
fig = px.line(df,x='x',y='y',color='xlimit',
range_x=[-1e17,1e17],
range_y=[0,1],
width=400,
height=400,)
fig.update_traces(opacity=0.5)
fig.show()
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用提供的 DataFrame、较窄的 range_x 值和 plotly.js v2.27.0,在 Jupyter notebook 中复现该问题。比较各示例范围中渲染出的线,并追踪该行为是源于 plotly.py px.line 路径还是 plotly.js 渲染;当提供的案例中的大范围线条能够一致地渲染时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, jupyter-notebook, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100