@@ -180,13 +180,16 @@ def validate_colors(colors, colors_list=None):
180
180
"""
181
181
Validates color(s) and returns an error for invalid color(s)
182
182
183
- :param (list) colors_list: whether a singleton color or a list/tuple of
183
+ :param (str|tuple|list) colors: either a plotly scale name, an rgb or hex
184
+ color, a color tuple or a list/tuple of colors
185
+ :param (list) colors_list: whether a single color or a list/tuple of
184
186
colors is inputted, all the color types are appended to colors_list
185
187
so they can be easily iterated through for validation
186
188
"""
187
189
if colors_list is None :
188
190
colors_list = []
189
191
192
+ # if colors is a single color, put into colors_list
190
193
if isinstance (colors , str ):
191
194
if colors in PLOTLY_SCALES :
192
195
return
@@ -250,6 +253,8 @@ def convert_colors_to_same_type(colors, colortype='rgb', scale=None,
250
253
be coverted to the selected colortype. If colors is None, then there is an
251
254
option to return portion of the DEFAULT_PLOTLY_COLORS
252
255
256
+ :param (str|tuple|list) colors: either a plotly scale name, an rgb or hex
257
+ color, a color tuple or a list/tuple of colors
253
258
:param (list) colors_list: see docs for validate_colors()
254
259
:param (list) scale: see docs for validate_scale_values()
255
260
@@ -327,42 +332,40 @@ def convert_colors_to_same_type(colors, colortype='rgb', scale=None,
327
332
'for your colortype variable.' )
328
333
329
334
330
- def convert_dict_colors_to_same_type (colors , colortype = 'rgb' ):
335
+ def convert_dict_colors_to_same_type (colors_dict , colortype = 'rgb' ):
331
336
"""
332
- Converts color(s) to the specified color type
337
+ Converts a colors in a dictioanry of colors to the specified color type
333
338
334
- Takes a single color or an iterable of colors and outputs a list of the
335
- color(s) converted all to an rgb or tuple color type. If colors is a
336
- Plotly Scale name then the cooresponding colorscale will be outputted
339
+ :param (dict) colors_dict: a dictioanry whose values are single colors
337
340
"""
338
- for key in colors :
339
- if '#' in colors [key ]:
340
- colors [key ] = color_parser (
341
- colors [key ], hex_to_rgb
341
+ for key in colors_dict :
342
+ if '#' in colors_dict [key ]:
343
+ colors_dict [key ] = color_parser (
344
+ colors_dict [key ], hex_to_rgb
342
345
)
343
- colors [key ] = color_parser (
344
- colors [key ], label_rgb
346
+ colors_dict [key ] = color_parser (
347
+ colors_dict [key ], label_rgb
345
348
)
346
349
347
- elif isinstance (colors [key ], tuple ):
348
- colors [key ] = color_parser (
349
- colors [key ], convert_to_RGB_255
350
+ elif isinstance (colors_dict [key ], tuple ):
351
+ colors_dict [key ] = color_parser (
352
+ colors_dict [key ], convert_to_RGB_255
350
353
)
351
- colors [key ] = color_parser (
352
- colors [key ], label_rgb
354
+ colors_dict [key ] = color_parser (
355
+ colors_dict [key ], label_rgb
353
356
)
354
357
355
358
if colortype == 'rgb' :
356
- return colors
359
+ return colors_dict
357
360
elif colortype == 'tuple' :
358
- for key in colors :
359
- colors [key ] = color_parser (
360
- colors [key ], unlabel_rgb
361
+ for key in colors_dict :
362
+ colors_dict [key ] = color_parser (
363
+ colors_dict [key ], unlabel_rgb
361
364
)
362
- colors [key ] = color_parser (
363
- colors [key ], unconvert_from_RGB_255
365
+ colors_dict [key ] = color_parser (
366
+ colors_dict [key ], unconvert_from_RGB_255
364
367
)
365
- return colors
368
+ return colors_dict
366
369
else :
367
370
raise exceptions .PlotlyError ('You must select either rgb or tuple '
368
371
'for your colortype variable.' )
@@ -406,6 +409,8 @@ def make_colorscale(colors, scale=None, colorscale=None):
406
409
list, it must be the same legnth as colors and must contain all floats
407
410
For documentation regarding to the form of the output, see
408
411
https://plot.ly/python/reference/#mesh3d-colorscale
412
+
413
+ :param (list) colors: a list of single colors
409
414
"""
410
415
if colorscale is None :
411
416
colorscale = []
0 commit comments