Skip to content

Commit 53f44be

Browse files
committed
made more documentation on colors param in colors.py and redid some examples in string docs (tools.py)
1 parent 9a701a2 commit 53f44be

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

Diff for: plotly/colors.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,16 @@ def validate_colors(colors, colors_list=None):
180180
"""
181181
Validates color(s) and returns an error for invalid color(s)
182182
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
184186
colors is inputted, all the color types are appended to colors_list
185187
so they can be easily iterated through for validation
186188
"""
187189
if colors_list is None:
188190
colors_list = []
189191

192+
# if colors is a single color, put into colors_list
190193
if isinstance(colors, str):
191194
if colors in PLOTLY_SCALES:
192195
return
@@ -250,6 +253,8 @@ def convert_colors_to_same_type(colors, colortype='rgb', scale=None,
250253
be coverted to the selected colortype. If colors is None, then there is an
251254
option to return portion of the DEFAULT_PLOTLY_COLORS
252255
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
253258
:param (list) colors_list: see docs for validate_colors()
254259
:param (list) scale: see docs for validate_scale_values()
255260
@@ -327,42 +332,40 @@ def convert_colors_to_same_type(colors, colortype='rgb', scale=None,
327332
'for your colortype variable.')
328333

329334

330-
def convert_dict_colors_to_same_type(colors, colortype='rgb'):
335+
def convert_dict_colors_to_same_type(colors_dict, colortype='rgb'):
331336
"""
332-
Converts color(s) to the specified color type
337+
Converts a colors in a dictioanry of colors to the specified color type
333338
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
337340
"""
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
342345
)
343-
colors[key] = color_parser(
344-
colors[key], label_rgb
346+
colors_dict[key] = color_parser(
347+
colors_dict[key], label_rgb
345348
)
346349

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
350353
)
351-
colors[key] = color_parser(
352-
colors[key], label_rgb
354+
colors_dict[key] = color_parser(
355+
colors_dict[key], label_rgb
353356
)
354357

355358
if colortype == 'rgb':
356-
return colors
359+
return colors_dict
357360
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
361364
)
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
364367
)
365-
return colors
368+
return colors_dict
366369
else:
367370
raise exceptions.PlotlyError('You must select either rgb or tuple '
368371
'for your colortype variable.')
@@ -406,6 +409,8 @@ def make_colorscale(colors, scale=None, colorscale=None):
406409
list, it must be the same legnth as colors and must contain all floats
407410
For documentation regarding to the form of the output, see
408411
https://plot.ly/python/reference/#mesh3d-colorscale
412+
413+
:param (list) colors: a list of single colors
409414
"""
410415
if colorscale is None:
411416
colorscale = []

Diff for: plotly/tools.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
35213521
35223522
# Create a figure
35233523
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3524-
colormap="Blues",
3524+
colormap="Rainbow",
35253525
simplices=simplices)
35263526
# Plot the data
35273527
py.iplot(fig1, filename='trisurf-plot-sphere')
@@ -3554,7 +3554,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
35543554
35553555
# Create a figure
35563556
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3557-
colormap="Greys",
3557+
colormap="Viridis",
35583558
simplices=simplices)
35593559
# Plot the data
35603560
py.iplot(fig1, filename='trisurf-plot-torus')
@@ -3625,9 +3625,10 @@ def dist_origin(x, y, z):
36253625
36263626
# Create a figure
36273627
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3628-
colormap=['#604d9e',
3629-
'rgb(50, 150, 255)',
3630-
(0.2, 0.2, 0.8)],
3628+
colormap=['#FFFFFF', '#E4FFFE',
3629+
'#A4F6F9', '#FF99FE',
3630+
'#BA52ED'],
3631+
scale=[0, 0.6, 0.71, 0.89, 1],
36313632
simplices=simplices,
36323633
color_func=dist_origin)
36333634
# Plot the data

0 commit comments

Comments
 (0)