Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77a2af4

Browse files
committed
Adding tools changes
1 parent eaa2169 commit 77a2af4

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

plotly/tools.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,9 +1509,27 @@ def _map_z2color(zval, colormap, vmin, vmax):
15091509
# find distance t of zval from vmin to vmax where the distance
15101510
# is normalized to be between 0 and 1
15111511
t = (zval - vmin)/float((vmax - vmin))
1512-
t_color = FigureFactory._find_intermediate_color(colormap[0],
1513-
colormap[1],
1514-
t)
1512+
1513+
# for colormaps of more than 2 colors, find adjacent colors in color
1514+
# map that the intermediate color is between
1515+
num_steps = len(colormap) - 1
1516+
step = 1./num_steps
1517+
1518+
if t == 1.0:
1519+
t_color = FigureFactory._find_intermediate_color(
1520+
colormap[int(t/step) - 1],
1521+
colormap[int(t/step)],
1522+
t
1523+
)
1524+
else:
1525+
new_t = (t - int(t/step)*step)/float(step)
1526+
1527+
t_color = FigureFactory._find_intermediate_color(
1528+
colormap[int(t/step)],
1529+
colormap[int(t/step) + 1],
1530+
new_t
1531+
)
1532+
15151533
t_color = (t_color[0]*255.0, t_color[1]*255.0, t_color[2]*255.0)
15161534
labelled_color = 'rgb{}'.format(t_color)
15171535

0 commit comments

Comments
 (0)