Skip to content

Commit f98da6a

Browse files
committed
Commented out current theme-index-test//created test for no index- no theme
1 parent 84fc4c4 commit f98da6a

File tree

2 files changed

+147
-11
lines changed

2 files changed

+147
-11
lines changed

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,11 @@ def test_valid_endpts(self):
693693
df, use_theme=True, index='a',
694694
palette='Blues', endpts=[2, 1])
695695

696+
"""
696697
def test_scatter_plot_matrix_kwargs(self):
697698
698699
# check if test scatter plot matrix matches with
699700
# the expected output
700-
701701
df = pd.DataFrame([[2, 'Apple'], [6, 'Pear'],
702702
[-15, 'Apple'], [5, 'Pear'],
703703
[-2, 'Apple'], [0, 'Apple']],
@@ -735,6 +735,77 @@ def test_scatter_plot_matrix_kwargs(self):
735735
'title': 'Numbers'}}
736736
}
737737
738+
self.assert_dict_equal(test_scatter_plot_matrix['data'][0],
739+
exp_scatter_plot_matrix['data'][0])
740+
741+
self.assert_dict_equal(test_scatter_plot_matrix['data'][1],
742+
exp_scatter_plot_matrix['data'][1])
743+
744+
self.assert_dict_equal(test_scatter_plot_matrix['layout'],
745+
exp_scatter_plot_matrix['layout'])
746+
"""
747+
748+
def test_scatter_plot_matrix(self):
749+
750+
# check if test scatter plot matrix without index or theme matches
751+
# with the expected output
752+
df = pd.DataFrame([[2, 'Apple'], [6, 'Pear'],
753+
[-15, 'Apple'], [5, 'Pear'],
754+
[-2, 'Apple'], [0, 'Apple']],
755+
columns=['Numbers', 'Fruit'])
756+
757+
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
758+
df, diag='scatter', height=1000, width=1000, size=13,
759+
title='Scatterplot Matrix', use_theme=False
760+
)
761+
762+
exp_scatter_plot_matrix = {
763+
'data': [{'marker': {'size': 13},
764+
'mode': 'markers',
765+
'showlegend': False,
766+
'type': 'scatter',
767+
'x': [2, 6, -15, 5, -2, 0],
768+
'xaxis': 'x1',
769+
'y': [2, 6, -15, 5, -2, 0],
770+
'yaxis': 'y1'},
771+
{'marker': {'size': 13},
772+
'mode': 'markers',
773+
'showlegend': False,
774+
'type': 'scatter',
775+
'x': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
776+
'xaxis': 'x2',
777+
'y': [2, 6, -15, 5, -2, 0],
778+
'yaxis': 'y2'},
779+
{'marker': {'size': 13},
780+
'mode': 'markers',
781+
'showlegend': False,
782+
'type': 'scatter',
783+
'x': [2, 6, -15, 5, -2, 0],
784+
'xaxis': 'x3',
785+
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
786+
'yaxis': 'y3'},
787+
{'marker': {'size': 13},
788+
'mode': 'markers',
789+
'showlegend': False,
790+
'type': 'scatter',
791+
'x': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
792+
'xaxis': 'x4',
793+
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
794+
'yaxis': 'y4'}],
795+
'layout': {'height': 1000,
796+
'showlegend': True,
797+
'title': 'Scatterplot Matrix',
798+
'width': 1000,
799+
'xaxis1': {'anchor': 'y1', 'domain': [0.0, 0.45]},
800+
'xaxis2': {'anchor': 'y2', 'domain': [0.55, 1.0]},
801+
'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.45], 'title': 'Numbers'},
802+
'xaxis4': {'anchor': 'y4', 'domain': [0.55, 1.0], 'title': 'Fruit'},
803+
'yaxis1': {'anchor': 'x1', 'domain': [0.575, 1.0], 'title': 'Numbers'},
804+
'yaxis2': {'anchor': 'x2', 'domain': [0.575, 1.0]},
805+
'yaxis3': {'anchor': 'x3', 'domain': [0.0, 0.425], 'title': 'Fruit'},
806+
'yaxis4': {'anchor': 'x4', 'domain': [0.0, 0.425]}}
807+
}
808+
738809
self.assert_dict_equal(test_scatter_plot_matrix['data'][0],
739810
exp_scatter_plot_matrix['data'][0])
740811

plotly/tools.py

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
from plotly.files import (CONFIG_FILE, CREDENTIALS_FILE, FILE_CONTENT,
2323
GRAPH_REFERENCE_FILE, check_file_permissions)
2424

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)']
2530

2631
# Warning format
2732
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):
14251430
_DEFAULT_INCREASING_COLOR = '#3D9970' # http://clrs.cc
14261431
_DEFAULT_DECREASING_COLOR = '#FF4136'
14271432

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-
14341433
DIAG_CHOICES = ['scatter', 'histogram', 'box']
14351434

14361435

@@ -1455,6 +1454,11 @@ def _scatterplot(dataframe, headers,
14551454
diag, size,
14561455
height, width,
14571456
title, **kwargs):
1457+
"""
1458+
Returns fig for scatterplotmatrix without index or theme.
1459+
Refer to FigureFactory.create_scatterplotmatrix() for docstring.
1460+
"""
1461+
14581462
from plotly.graph_objs import graph_objs
14591463
dim = len(dataframe)
14601464
fig = make_subplots(rows=dim, cols=dim)
@@ -1527,6 +1531,10 @@ def _scatterplot_index(dataframe, headers,
15271531
title,
15281532
index, index_vals,
15291533
**kwargs):
1534+
"""
1535+
Returns fig for scatterplotmatrix with an index and no theme.
1536+
Refer to FigureFactory.create_scatterplotmatrix() for docstring.
1537+
"""
15301538
from plotly.graph_objs import graph_objs
15311539
dim = len(dataframe)
15321540
fig = make_subplots(rows=dim, cols=dim)
@@ -1690,6 +1698,13 @@ def _scatterplot_index(dataframe, headers,
16901698
def _scatterplot_theme(dataframe, headers, diag, size, height, width,
16911699
title, index, index_vals, endpts,
16921700
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+
"""
16931708
from plotly.graph_objs import graph_objs
16941709
plotly_scales = {'Greys': ['rgb(0,0,0)', 'rgb(255,255,255)'],
16951710
'YlGnBu': ['rgb(8,29,88)', 'rgb(255,255,217)'],
@@ -1864,6 +1879,7 @@ def _scatterplot_theme(dataframe, headers, diag, size, height, width,
18641879
c_indx += 1
18651880
trace_list.append(unique_index_vals)
18661881
legend_param += 1
1882+
#return trace_list
18671883

18681884
trace_index = 0
18691885
indices = range(1, dim + 1)
@@ -2246,6 +2262,12 @@ def _scatterplot_theme(dataframe, headers, diag, size, height, width,
22462262

22472263
@staticmethod
22482264
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+
"""
22492271
from numbers import Number
22502272
if isinstance(index_vals[0], Number):
22512273
if not all(isinstance(item, Number) for item in index_vals):
@@ -2263,6 +2285,13 @@ def _validate_index(index_vals):
22632285

22642286
@staticmethod
22652287
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+
"""
22662295
from numbers import Number
22672296
for vector in array:
22682297
if isinstance(vector[0], Number):
@@ -2280,6 +2309,17 @@ def _validate_dataframe(array):
22802309

22812310
@staticmethod
22822311
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+
"""
22832323
if _pandas_imported is False:
22842324
raise ImportError("FigureFactory.scatterplotmatrix requires "
22852325
"a pandas DataFrame.")
@@ -2316,6 +2356,16 @@ def _validate_scatterplotmatrix(df, index, diag, **kwargs):
23162356

23172357
@staticmethod
23182358
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+
"""
23192369
length = len(endpts)
23202370
# Check if endpts is a list or tuple
23212371
if not (isinstance(endpts, (tuple)) or isinstance(endpts, (list))):
@@ -2351,8 +2401,11 @@ def _endpts_to_intervals(endpts):
23512401

23522402
@staticmethod
23532403
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+
"""
23562409
colors_255 = []
23572410

23582411
for color in colors:
@@ -2362,8 +2415,10 @@ def _convert_to_RGB_255(colors):
23622415

23632416
@staticmethod
23642417
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+
"""
23672422
diff_0 = float(tuple2[0] - tuple1[0])
23682423
incr_0 = diff_0/(n_colors - 1)
23692424
diff_1 = float(tuple2[1] - tuple1[1])
@@ -2382,6 +2437,10 @@ def _n_colors(tuple1, tuple2, n_colors):
23822437

23832438
@staticmethod
23842439
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+
"""
23852444
colors_label = []
23862445
for color in colors:
23872446
color_label = 'rgb{}'.format(color)
@@ -2391,6 +2450,12 @@ def _label_rgb(colors):
23912450

23922451
@staticmethod
23932452
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+
"""
23942459
unlabelled_colors = []
23952460
for color in colors:
23962461
str_vals = ''

0 commit comments

Comments
 (0)