plotly / plotly/plotly.py

create_trisurf raises an IndexError exception when one triangle's average height is very close to max height

未关闭
#3,323 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

When giving plotly.figure_factory.create_trisurf values where on triangle on the surface is very close to the maximum the function raises an IndexError. I'd expect a pretty plot instead.

Reproduction:

Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import plotly
>>> import plotly.figure_factory as ff
>>> import numpy as np
>>> plotly.__version__
'5.1.0'
>>> vmin, vmax = -0.8, 0.2
>>> face = np.nextafter(vmax, -vmax) # the last value less than vmax
>>> # define a simple shape which includes 3 triangles of constant value vmin, vmax and face
... 
>>> x = [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0]
>>> y = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
>>> z = [vmin, vmin, vmin, face, face, face, vmax, vmax, vmax]
>>> simplices = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]]
>>> ff.create_trisurf(x, y, z, simplices)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.6/site-packages/plotly/figure_factory/_trisurf.py", line 488, in create_trisurf
    plot_edges=plot_edges,
  File "/home/user/.local/lib/python3.6/site-packages/plotly/figure_factory/_trisurf.py", line 153, in trisurf
    mean_dists[index], colormap, scale, min_mean_dists, max_mean_dists
  File "/home/user/.local/lib/python3.6/site-packages/plotly/figure_factory/_trisurf.py", line 48, in map_face2color
    colormap[low_color_index + 1],
IndexError: list index out of range

Also attached a file does the same thing, as a .txt file instead of .py because that's what github supports in this context.
plotly_trisurf_indexerror.txt

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 plotly/figure_factory/_trisurf.py 开始,重点查看 map_face2color,traceback 报告的正是该处对 colormap 的越界访问。运行所提供的 Python 和 NumPy 复现代码,然后验证 create_trisurf 能够完成并生成图表,而不是引发 IndexError。

由索引模型根据 Issue 内容生成。

评估

技术栈
numpy, python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。