22
22
from plotly .files import (CONFIG_FILE , CREDENTIALS_FILE , FILE_CONTENT ,
23
23
GRAPH_REFERENCE_FILE , check_file_permissions )
24
24
25
+ DEFAULT_PLOTLY_COLORS = ['rgb(31, 119, 180)' , 'rgb(255, 127, 14)' ,
26
+ 'rgb(44, 160, 44)' , 'rgb(214, 39, 40)' ,
27
+ 'rgb(148, 103, 189)' , 'rgb(140, 86, 75)' ,
28
+ 'rgb(227, 119, 194)' , 'rgb(127, 127, 127)' ,
29
+ 'rgb(188, 189, 34)' , 'rgb(23, 190, 207)' ]
25
30
26
31
# Warning format
27
32
def warning_on_one_line (message , category , filename , lineno ,
@@ -1425,12 +1430,6 @@ def return_figure_from_figure_or_data(figure_or_data, validate_figure):
1425
1430
_DEFAULT_INCREASING_COLOR = '#3D9970' # http://clrs.cc
1426
1431
_DEFAULT_DECREASING_COLOR = '#FF4136'
1427
1432
1428
- DEFAULT_PLOTLY_COLORS = ['rgb(31, 119, 180)' , 'rgb(255, 127, 14)' ,
1429
- 'rgb(44, 160, 44)' , 'rgb(214, 39, 40)' ,
1430
- 'rgb(148, 103, 189)' , 'rgb(140, 86, 75)' ,
1431
- 'rgb(227, 119, 194)' , 'rgb(127, 127, 127)' ,
1432
- 'rgb(188, 189, 34)' , 'rgb(23, 190, 207)' ]
1433
-
1434
1433
DIAG_CHOICES = ['scatter' , 'histogram' , 'box' ]
1435
1434
1436
1435
@@ -1455,6 +1454,11 @@ def _scatterplot(dataframe, headers,
1455
1454
diag , size ,
1456
1455
height , width ,
1457
1456
title , ** kwargs ):
1457
+ """
1458
+ Returns fig for scatterplotmatrix without index or theme.
1459
+ Refer to FigureFactory.create_scatterplotmatrix() for docstring.
1460
+ """
1461
+
1458
1462
from plotly .graph_objs import graph_objs
1459
1463
dim = len (dataframe )
1460
1464
fig = make_subplots (rows = dim , cols = dim )
@@ -1527,6 +1531,10 @@ def _scatterplot_index(dataframe, headers,
1527
1531
title ,
1528
1532
index , index_vals ,
1529
1533
** kwargs ):
1534
+ """
1535
+ Returns fig for scatterplotmatrix with an index and no theme.
1536
+ Refer to FigureFactory.create_scatterplotmatrix() for docstring.
1537
+ """
1530
1538
from plotly .graph_objs import graph_objs
1531
1539
dim = len (dataframe )
1532
1540
fig = make_subplots (rows = dim , cols = dim )
@@ -1690,6 +1698,13 @@ def _scatterplot_index(dataframe, headers,
1690
1698
def _scatterplot_theme (dataframe , headers , diag , size , height , width ,
1691
1699
title , index , index_vals , endpts ,
1692
1700
palette , ** kwargs ):
1701
+ """
1702
+ Returns fig for scatterplotmatrix with both index and theme.
1703
+ Refer to FigureFactory.create_scatterplotmatrix() for docstring.
1704
+
1705
+ :raises: (PlotlyError) If palette string is not a Plotly colorscale
1706
+ :raises: (PlotlyError) If palette is not a string or list
1707
+ """
1693
1708
from plotly .graph_objs import graph_objs
1694
1709
plotly_scales = {'Greys' : ['rgb(0,0,0)' , 'rgb(255,255,255)' ],
1695
1710
'YlGnBu' : ['rgb(8,29,88)' , 'rgb(255,255,217)' ],
@@ -1864,6 +1879,7 @@ def _scatterplot_theme(dataframe, headers, diag, size, height, width,
1864
1879
c_indx += 1
1865
1880
trace_list .append (unique_index_vals )
1866
1881
legend_param += 1
1882
+ #return trace_list
1867
1883
1868
1884
trace_index = 0
1869
1885
indices = range (1 , dim + 1 )
@@ -2246,6 +2262,12 @@ def _scatterplot_theme(dataframe, headers, diag, size, height, width,
2246
2262
2247
2263
@staticmethod
2248
2264
def _validate_index (index_vals ):
2265
+ """
2266
+ Validates if a list contains all numbers or all strings.
2267
+
2268
+ :raises: (PlotlyError) If there are any two items in the list whose
2269
+ types differ
2270
+ """
2249
2271
from numbers import Number
2250
2272
if isinstance (index_vals [0 ], Number ):
2251
2273
if not all (isinstance (item , Number ) for item in index_vals ):
@@ -2263,6 +2285,13 @@ def _validate_index(index_vals):
2263
2285
2264
2286
@staticmethod
2265
2287
def _validate_dataframe (array ):
2288
+ """
2289
+ Validates if for the lists in a dataframe, they contain all numbers
2290
+ or all strings.
2291
+
2292
+ :raises: (PlotlyError) If there are any two items in any list whose
2293
+ types differ
2294
+ """
2266
2295
from numbers import Number
2267
2296
for vector in array :
2268
2297
if isinstance (vector [0 ], Number ):
@@ -2280,6 +2309,17 @@ def _validate_dataframe(array):
2280
2309
2281
2310
@staticmethod
2282
2311
def _validate_scatterplotmatrix (df , index , diag , ** kwargs ):
2312
+ """
2313
+ Validates basic inputs for FigureFactory.create_scatterplotmatrix()
2314
+
2315
+ :raises: (PlotlyError) If pandas is not imported
2316
+ :raises: (PlotlyError) If pandas dataframe is not inputted
2317
+ :raises: (PlotlyError) If pandas dataframe has <= 1 columns
2318
+ :raises: (PlotlyError) If diagonal plot choice (diag) is not one of
2319
+ the viable options
2320
+ :raises: (PlotlyError) If kwargs contains 'size', 'color' or
2321
+ 'colorscale'
2322
+ """
2283
2323
if _pandas_imported is False :
2284
2324
raise ImportError ("FigureFactory.scatterplotmatrix requires "
2285
2325
"a pandas DataFrame." )
@@ -2316,6 +2356,16 @@ def _validate_scatterplotmatrix(df, index, diag, **kwargs):
2316
2356
2317
2357
@staticmethod
2318
2358
def _endpts_to_intervals (endpts ):
2359
+ """
2360
+ Accepts a list or tuple of sequentially increasing numbers and returns
2361
+ a list representation of the mathematical intervals with these numbers
2362
+ as endpoints. For example, [1, 4, 6] returns [[1, 4], [4, 6]]
2363
+
2364
+ :raises: (PlotlyError) If input is not a list or tuple
2365
+ :raises: (PlotlyError) If the input contains a string
2366
+ :raises: (PlotlyError) If any number does not increase after the
2367
+ previous one in the sequence
2368
+ """
2319
2369
length = len (endpts )
2320
2370
# Check if endpts is a list or tuple
2321
2371
if not (isinstance (endpts , (tuple )) or isinstance (endpts , (list ))):
@@ -2351,8 +2401,11 @@ def _endpts_to_intervals(endpts):
2351
2401
2352
2402
@staticmethod
2353
2403
def _convert_to_RGB_255 (colors ):
2354
- # convert a list of color tuples in normalized space to
2355
- # to a list of RGB_255 converted tuples
2404
+ """
2405
+ Takes a list of color tuples where each element is between 0 and 1
2406
+ and returns the same list where each tuple element is normalized to be
2407
+ between 0 and 255
2408
+ """
2356
2409
colors_255 = []
2357
2410
2358
2411
for color in colors :
@@ -2362,8 +2415,10 @@ def _convert_to_RGB_255(colors):
2362
2415
2363
2416
@staticmethod
2364
2417
def _n_colors (tuple1 , tuple2 , n_colors ):
2365
- # Split two color tuples in normalized
2366
- # space into n_colors # of intermediate color tuples
2418
+ """
2419
+ Accepts two color tuples and returns a list of n_colors colors
2420
+ which form the intermediate points between tuple1 and tuple2
2421
+ """
2367
2422
diff_0 = float (tuple2 [0 ] - tuple1 [0 ])
2368
2423
incr_0 = diff_0 / (n_colors - 1 )
2369
2424
diff_1 = float (tuple2 [1 ] - tuple1 [1 ])
@@ -2382,6 +2437,10 @@ def _n_colors(tuple1, tuple2, n_colors):
2382
2437
2383
2438
@staticmethod
2384
2439
def _label_rgb (colors ):
2440
+ """
2441
+ Takes a list of two color tuples of the form (a, b, c) and returns the
2442
+ same list with each tuple replaced by a string 'rgb(a, b, c)'
2443
+ """
2385
2444
colors_label = []
2386
2445
for color in colors :
2387
2446
color_label = 'rgb{}' .format (color )
@@ -2391,6 +2450,12 @@ def _label_rgb(colors):
2391
2450
2392
2451
@staticmethod
2393
2452
def _unlabel_rgb (colors ):
2453
+ """
2454
+ This function takes a list of two 'rgb(a, b, c)' color strings and
2455
+ returns a list of the color tuples in tuple form without the 'rgb'
2456
+ label. In particular, the output is a list of two tuples of the form
2457
+ (a, b, c)
2458
+ """
2394
2459
unlabelled_colors = []
2395
2460
for color in colors :
2396
2461
str_vals = ''
0 commit comments