@@ -627,18 +627,6 @@ def test_valid_colormap(self):
627
627
self .assertRaises (PlotlyError , tls .FigureFactory .create_trisurf ,
628
628
x , y , z , simplices , colormap = 'foo' )
629
629
630
- # check that colormap is a list, if not a string
631
-
632
- pattern1 = (
633
- "If 'colormap' is a list, then its items must be tripets of the "
634
- "form a,b,c or 'rgbx,y,z' where a,b,c are between 0 and 1 "
635
- "inclusive and x,y,z are between 0 and 255 inclusive."
636
- )
637
-
638
- self .assertRaisesRegexp (PlotlyError , pattern1 ,
639
- tls .FigureFactory .create_trisurf ,
640
- x , y , z , simplices , colormap = 3 )
641
-
642
630
# check: if colormap is a list of rgb color strings, make sure the
643
631
# entries of each color are no greater than 255.0
644
632
@@ -650,20 +638,31 @@ def test_valid_colormap(self):
650
638
self .assertRaisesRegexp (PlotlyError , pattern2 ,
651
639
tls .FigureFactory .create_trisurf ,
652
640
x , y , z , simplices ,
653
- colormap = ['rgb(1, 2, 3)' , 'rgb( 4, 5, 600)' ])
641
+ colormap = ['rgb(4, 5, 600)' ])
654
642
655
643
# check: if colormap is a list of tuple colors, make sure the entries
656
644
# of each tuple are no greater than 1.0
657
645
658
646
pattern3 = (
659
- "Whoops! The elements in your rgb colormap tuples "
660
- "cannot exceed 1.0."
647
+ "Whoops! The elements in your colormap tuples cannot exceed 1.0."
661
648
)
662
649
663
650
self .assertRaisesRegexp (PlotlyError , pattern3 ,
664
651
tls .FigureFactory .create_trisurf ,
665
652
x , y , z , simplices ,
666
- colormap = [(0.2 , 0.4 , 0.6 ), (0.8 , 1.0 , 1.2 )])
653
+ colormap = [(0.8 , 1.0 , 1.2 )])
654
+
655
+ # check:
656
+
657
+ pattern4 = (
658
+ "You must input a valid colormap. Valid types include a plotly "
659
+ "scale, rgb, hex or tuple color, or lastly a list of any color "
660
+ "types."
661
+ )
662
+
663
+ self .assertRaisesRegexp (PlotlyError , pattern4 ,
664
+ tls .FigureFactory .create_trisurf ,
665
+ x , y , z , simplices , colormap = 1 )
667
666
668
667
def test_trisurf_all_args (self ):
669
668
@@ -865,27 +864,55 @@ def test_same_data_in_index(self):
865
864
tls .FigureFactory .create_scatterplotmatrix ,
866
865
df , index = 'apple' )
867
866
868
- def test_valid_palette (self ):
867
+ def test_valid_colormap (self ):
869
868
870
- # check: the palette argument is in a acceptable form
869
+ # check: the colormap argument is in a valid form
871
870
df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]],
872
871
columns = ['a' , 'b' , 'c' ])
873
872
874
- self .assertRaisesRegexp (PlotlyError , "You must pick a valid "
875
- "plotly colorscale name." ,
876
- tls .FigureFactory .create_scatterplotmatrix ,
877
- df , use_theme = True , index = 'a' ,
878
- 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' )
879
877
880
878
pattern = (
881
- "The items of 'palette' must be tripets of the form a,b,c or "
882
- "'rgbx,y,z' where a,b,c belong to the interval 0,1 and x,y,z "
883
- "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 ."
884
882
)
885
883
884
+ # check: accepted data type for colormap
886
885
self .assertRaisesRegexp (PlotlyError , pattern ,
887
886
tls .FigureFactory .create_scatterplotmatrix ,
888
- 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' )
889
916
890
917
def test_valid_endpts (self ):
891
918
@@ -900,20 +927,35 @@ def test_valid_endpts(self):
900
927
901
928
self .assertRaisesRegexp (PlotlyError , pattern ,
902
929
tls .FigureFactory .create_scatterplotmatrix ,
903
- df , use_theme = True , index = 'a' ,
904
- palette = 'Blues' , endpts = 'foo' )
930
+ df , index = 'a' , colormap = 'Hot' , endpts = 'foo' )
905
931
906
932
# check: the endpts are a list of numbers
907
933
self .assertRaisesRegexp (PlotlyError , pattern ,
908
934
tls .FigureFactory .create_scatterplotmatrix ,
909
- df , use_theme = True , index = 'a' ,
910
- palette = 'Blues' , endpts = ['a' ])
935
+ df , index = 'a' , colormap = 'Hot' , endpts = ['a' ])
911
936
912
937
# check: endpts is a list of INCREASING numbers
913
938
self .assertRaisesRegexp (PlotlyError , pattern ,
914
939
tls .FigureFactory .create_scatterplotmatrix ,
915
- df , use_theme = True , index = 'a' ,
916
- 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 )
917
959
918
960
def test_scatter_plot_matrix (self ):
919
961
@@ -926,7 +968,7 @@ def test_scatter_plot_matrix(self):
926
968
927
969
test_scatter_plot_matrix = tls .FigureFactory .create_scatterplotmatrix (
928
970
df = df , diag = 'scatter' , height = 1000 , width = 1000 , size = 13 ,
929
- title = 'Scatterplot Matrix' , use_theme = False
971
+ title = 'Scatterplot Matrix'
930
972
)
931
973
932
974
exp_scatter_plot_matrix = {
@@ -1020,17 +1062,17 @@ def test_scatter_plot_matrix_kwargs(self):
1020
1062
test_scatter_plot_matrix = tls .FigureFactory .create_scatterplotmatrix (
1021
1063
df , index = 'Fruit' , endpts = [- 10 , - 1 ], diag = 'histogram' ,
1022
1064
height = 1000 , width = 1000 , size = 13 , title = 'Scatterplot Matrix' ,
1023
- use_theme = True , palette = 'YlOrRd' , marker = dict (symbol = 136 )
1065
+ colormap = 'YlOrRd' , marker = dict (symbol = 136 )
1024
1066
)
1025
1067
1026
1068
exp_scatter_plot_matrix = {
1027
- 'data' : [{'marker' : {'color' : 'rgb(128.0, 0.0, 38.0 )' },
1069
+ 'data' : [{'marker' : {'color' : 'rgb(128,0,38 )' },
1028
1070
'showlegend' : False ,
1029
1071
'type' : 'histogram' ,
1030
1072
'x' : [2 , - 15 , - 2 , 0 ],
1031
1073
'xaxis' : 'x1' ,
1032
1074
'yaxis' : 'y1' },
1033
- {'marker' : {'color' : 'rgb(255.0, 255.0, 204.0 )' },
1075
+ {'marker' : {'color' : 'rgb(255, 255, 204)' },
1034
1076
'showlegend' : False ,
1035
1077
'type' : 'histogram' ,
1036
1078
'x' : [6 , 5 ],
0 commit comments