Skip to content

Commit 5c11b56

Browse files
committed
Added Plus-2-Color compatibility to Scatterplotmatrix//rewrote string docs//reworked some helper functions to accept color values in addition to lists of color values
1 parent 4d3f787 commit 5c11b56

File tree

2 files changed

+432
-237
lines changed

2 files changed

+432
-237
lines changed

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -864,27 +864,55 @@ def test_same_data_in_index(self):
864864
tls.FigureFactory.create_scatterplotmatrix,
865865
df, index='apple')
866866

867-
def test_valid_palette(self):
867+
def test_valid_colormap(self):
868868

869-
# check: the palette argument is in a acceptable form
869+
# check: the colormap argument is in a valid form
870870
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
871871
columns=['a', 'b', 'c'])
872872

873-
self.assertRaisesRegexp(PlotlyError, "You must pick a valid "
874-
"plotly colorscale name.",
875-
tls.FigureFactory.create_scatterplotmatrix,
876-
df, use_theme=True, index='a',
877-
palette='fake_scale')
873+
# check: valid plotly scalename is entered
874+
self.assertRaises(PlotlyError,
875+
tls.FigureFactory.create_scatterplotmatrix,
876+
df, index='a', colormap='fake_scale')
878877

879878
pattern = (
880-
"The items of 'palette' must be tripets of the form a,b,c or "
881-
"'rgbx,y,z' where a,b,c belong to the interval 0,1 and x,y,z "
882-
"belong to 0,255."
879+
"You must input a valid colormap. Valid types include a plotly "
880+
"scale, rgb, hex or tuple color, a list of any color types, or a "
881+
"dictionary with index names each assigned to a color."
883882
)
884883

884+
# check: accepted data type for colormap
885885
self.assertRaisesRegexp(PlotlyError, pattern,
886886
tls.FigureFactory.create_scatterplotmatrix,
887-
df, use_theme=True, palette=1, index='c')
887+
df, colormap=1)
888+
889+
pattern_rgb = (
890+
"Whoops! The elements in your rgb colormap tuples cannot "
891+
"exceed 255.0."
892+
)
893+
894+
# check: proper 'rgb' color
895+
self.assertRaisesRegexp(PlotlyError, pattern_rgb,
896+
tls.FigureFactory.create_scatterplotmatrix,
897+
df, colormap='rgb(500, 1, 1)', index='c')
898+
899+
self.assertRaisesRegexp(PlotlyError, pattern_rgb,
900+
tls.FigureFactory.create_scatterplotmatrix,
901+
df, colormap=['rgb(500, 1, 1)'], index='c')
902+
903+
pattern_tuple = (
904+
"Whoops! The elements in your colormap tuples cannot "
905+
"exceed 1.0."
906+
)
907+
908+
# check: proper color tuple
909+
self.assertRaisesRegexp(PlotlyError, pattern_tuple,
910+
tls.FigureFactory.create_scatterplotmatrix,
911+
df, colormap=(2, 1, 1), index='c')
912+
913+
self.assertRaisesRegexp(PlotlyError, pattern_tuple,
914+
tls.FigureFactory.create_scatterplotmatrix,
915+
df, colormap=[(2, 1, 1)], index='c')
888916

889917
def test_valid_endpts(self):
890918

@@ -899,20 +927,35 @@ def test_valid_endpts(self):
899927

900928
self.assertRaisesRegexp(PlotlyError, pattern,
901929
tls.FigureFactory.create_scatterplotmatrix,
902-
df, use_theme=True, index='a',
903-
palette='Blues', endpts='foo')
930+
df, index='a', colormap='Hot', endpts='foo')
904931

905932
# check: the endpts are a list of numbers
906933
self.assertRaisesRegexp(PlotlyError, pattern,
907934
tls.FigureFactory.create_scatterplotmatrix,
908-
df, use_theme=True, index='a',
909-
palette='Blues', endpts=['a'])
935+
df, index='a', colormap='Hot', endpts=['a'])
910936

911937
# check: endpts is a list of INCREASING numbers
912938
self.assertRaisesRegexp(PlotlyError, pattern,
913939
tls.FigureFactory.create_scatterplotmatrix,
914-
df, use_theme=True, index='a',
915-
palette='Blues', endpts=[2, 1])
940+
df, index='a', colormap='Hot', endpts=[2, 1])
941+
942+
def test_dictionary_colormap(self):
943+
944+
# if colormap is a dictionary, make sure it all the values in the
945+
# index column are keys in colormap
946+
df = pd.DataFrame([['apple', 'happy'], ['pear', 'sad']],
947+
columns=['Fruit', 'Emotion'])
948+
949+
colormap = {'happy': 'rgb(5, 5, 5)'}
950+
951+
pattern = (
952+
"If colormap is a dictionary, all the names in the index "
953+
"must be keys."
954+
)
955+
956+
self.assertRaisesRegexp(PlotlyError, pattern,
957+
tls.FigureFactory.create_scatterplotmatrix,
958+
df, index='Emotion', colormap=colormap)
916959

917960
def test_scatter_plot_matrix(self):
918961

@@ -925,7 +968,7 @@ def test_scatter_plot_matrix(self):
925968

926969
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
927970
df=df, diag='scatter', height=1000, width=1000, size=13,
928-
title='Scatterplot Matrix', use_theme=False
971+
title='Scatterplot Matrix'
929972
)
930973

931974
exp_scatter_plot_matrix = {
@@ -1019,17 +1062,17 @@ def test_scatter_plot_matrix_kwargs(self):
10191062
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
10201063
df, index='Fruit', endpts=[-10, -1], diag='histogram',
10211064
height=1000, width=1000, size=13, title='Scatterplot Matrix',
1022-
use_theme=True, palette='YlOrRd', marker=dict(symbol=136)
1065+
colormap='YlOrRd', marker=dict(symbol=136)
10231066
)
10241067

10251068
exp_scatter_plot_matrix = {
1026-
'data': [{'marker': {'color': 'rgb(128.0, 0.0, 38.0)'},
1069+
'data': [{'marker': {'color': 'rgb(128,0,38)'},
10271070
'showlegend': False,
10281071
'type': 'histogram',
10291072
'x': [2, -15, -2, 0],
10301073
'xaxis': 'x1',
10311074
'yaxis': 'y1'},
1032-
{'marker': {'color': 'rgb(255.0, 255.0, 204.0)'},
1075+
{'marker': {'color': 'rgb(255,255,204)'},
10331076
'showlegend': False,
10341077
'type': 'histogram',
10351078
'x': [6, 5],

0 commit comments

Comments
 (0)