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

Skip to content

Commit 13a84a4

Browse files
committed
Added first changes
1 parent fd85153 commit 13a84a4

File tree

1 file changed

+23
-66
lines changed

1 file changed

+23
-66
lines changed

plotly/tools.py

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,25 +1510,28 @@ def _map_z2color(zval, colormap, vmin, vmax):
15101510
# is normalized to be between 0 and 1
15111511
t = (zval - vmin)/float((vmax - vmin))
15121512

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-
)
1513+
# for colormaps of more than 2 colors, find two closest colors based
1514+
# on relative position between vmin and vmax
1515+
if len(colormap) == 1:
1516+
t_color = colormap[0]
15241517
else:
1525-
new_t = (t - int(t/step)*step)/float(step)
1518+
num_steps = len(colormap) - 1
1519+
step = 1./num_steps
1520+
1521+
if t == 1.0:
1522+
t_color = FigureFactory._find_intermediate_color(
1523+
colormap[int(t/step) - 1],
1524+
colormap[int(t/step)],
1525+
t
1526+
)
1527+
else:
1528+
new_t = (t - int(t/step)*step)/float(step)
15261529

1527-
t_color = FigureFactory._find_intermediate_color(
1528-
colormap[int(t/step)],
1529-
colormap[int(t/step) + 1],
1530-
new_t
1531-
)
1530+
t_color = FigureFactory._find_intermediate_color(
1531+
colormap[int(t/step)],
1532+
colormap[int(t/step) + 1],
1533+
new_t
1534+
)
15321535

15331536
t_color = (t_color[0]*255.0, t_color[1]*255.0, t_color[2]*255.0)
15341537
labelled_color = 'rgb{}'.format(t_color)
@@ -1817,33 +1820,6 @@ def dist_origin(x, y, z):
18171820
'Electric': ['rgb(0,0,0)', 'rgb(255,250,220)'],
18181821
'Viridis': ['rgb(68,1,84)', 'rgb(253,231,37)']}
18191822

1820-
if isinstance(colors, str):
1821-
if colors in plotly_scales:
1822-
colors = plotly_scales[colors]
1823-
else:
1824-
if ('rgb' not in colors) and ('#' not in colors):
1825-
raise exceptions.PlotlyError("If you input a string "
1826-
"for 'colors', it must "
1827-
"either be a Plotly "
1828-
"colorscale, an 'rgb' "
1829-
"color, or a hex color.")
1830-
colors_list = []
1831-
colors_list.append(colors)
1832-
colors = colors_list
1833-
1834-
if not isinstance(colors, list):
1835-
raise exceptions.PlotlyError("'colors' needs to be either a "
1836-
"plotly colorscale string or a "
1837-
"list of at least two colors if "
1838-
"use_colorscale is True.")
1839-
if len(colors) <= 0:
1840-
raise exceptions.PlotlyError("Empty list of colors.")
1841-
1842-
if (not isinstance(data, list)) and data_header is None:
1843-
raise exceptions.PlotlyError("Please enter a string name for "
1844-
"data_header")
1845-
1846-
18471823
# Validate colormap
18481824
if colormap is None:
18491825
colormap = [DEFAULT_PLOTLY_COLORS[0],
@@ -1857,7 +1833,7 @@ def dist_origin(x, y, z):
18571833
colormap = FigureFactory._unlabel_rgb(colormap)
18581834
colormap = FigureFactory._unconvert_from_RGB_255(colormap)
18591835
else:
1860-
if ('rgb' not in colors) and ('#' not in colors):
1836+
if ('rgb' not in colormap) and ('#' not in colormap):
18611837
scale_keys = list(plotly_scales.keys())
18621838
raise exceptions.PlotlyError("If you input a string "
18631839
"for 'colormap', it must "
@@ -1870,27 +1846,8 @@ def dist_origin(x, y, z):
18701846
colors_list = []
18711847
colors_list.append(colormap)
18721848
colormap = colors_list
1873-
1874-
1875-
1876-
1877-
1878-
1879-
1880-
1881-
1882-
if isinstance(colormap, str):
1883-
if colormap not in plotly_scales:
1884-
scale_keys = list(plotly_scales.keys())
1885-
raise exceptions.PlotlyError("You must pick a valid "
1886-
"plotly colorscale "
1887-
"name from "
1888-
"{}".format(scale_keys))
1889-
1890-
colormap = [plotly_scales[colormap][0],
1891-
plotly_scales[colormap][1]]
1892-
colormap = FigureFactory._unlabel_rgb(colormap)
1893-
colormap = FigureFactory._unconvert_from_RGB_255(colormap)
1849+
colormap = FigureFactory._unlabel_rgb(colormap)
1850+
colormap = FigureFactory._unconvert_from_RGB_255(colormap)
18941851

18951852
else:
18961853
if not isinstance(colormap, list):

0 commit comments

Comments
 (0)