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

Skip to content

Commit fd85153

Browse files
committed
Added tools
1 parent 77a2af4 commit fd85153

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

plotly/tools.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,13 +1817,68 @@ def dist_origin(x, y, z):
18171817
'Electric': ['rgb(0,0,0)', 'rgb(255,250,220)'],
18181818
'Viridis': ['rgb(68,1,84)', 'rgb(253,231,37)']}
18191819

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+
18201847
# Validate colormap
18211848
if colormap is None:
18221849
colormap = [DEFAULT_PLOTLY_COLORS[0],
18231850
DEFAULT_PLOTLY_COLORS[1]]
18241851
colormap = FigureFactory._unlabel_rgb(colormap)
18251852
colormap = FigureFactory._unconvert_from_RGB_255(colormap)
18261853

1854+
if isinstance(colormap, str):
1855+
if colormap in plotly_scales:
1856+
colormap = plotly_scales[colormap]
1857+
colormap = FigureFactory._unlabel_rgb(colormap)
1858+
colormap = FigureFactory._unconvert_from_RGB_255(colormap)
1859+
else:
1860+
if ('rgb' not in colors) and ('#' not in colors):
1861+
scale_keys = list(plotly_scales.keys())
1862+
raise exceptions.PlotlyError("If you input a string "
1863+
"for 'colormap', it must "
1864+
"either be a Plotly "
1865+
"colorscale, an 'rgb' "
1866+
"color or a hex color."
1867+
"Valud plotly colorscale "
1868+
"names are {}".format(scale_keys))
1869+
# put colormap string into a list
1870+
colors_list = []
1871+
colors_list.append(colormap)
1872+
colormap = colors_list
1873+
1874+
1875+
1876+
1877+
1878+
1879+
1880+
1881+
18271882
if isinstance(colormap, str):
18281883
if colormap not in plotly_scales:
18291884
scale_keys = list(plotly_scales.keys())

0 commit comments

Comments
 (0)