plotly / plotly/plotly.py

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

Open
#3,323 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in plotly/figure_factory/_trisurf.py, especially map_face2color, where the traceback reports the out-of-range colormap access. Run the supplied Python and NumPy reproduction, then verify that create_trisurf completes and produces a plot instead of raising IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.