@@ -807,8 +807,7 @@ def make_subplots(rows=1, cols=1,
807
807
808
808
# Throw exception if non-valid kwarg is sent
809
809
VALID_KWARGS = ['horizontal_spacing' , 'vertical_spacing' ,
810
- 'specs' , 'insets' , 'subplot_titles' , 'column_width' ,
811
- 'row_width' ]
810
+ 'specs' , 'insets' , 'subplot_titles' , 'column_width' ]
812
811
for key in kwargs .keys ():
813
812
if key not in VALID_KWARGS :
814
813
raise Exception ("Invalid keyword argument: '{0}'" .format (key ))
@@ -908,24 +907,44 @@ def _checks(item, defaults):
908
907
)
909
908
_check_keys_and_fill ('insets' , insets , INSET_defaults )
910
909
911
- # Set width & height of each subplot cell (excluding padding)
912
- width = (1. - horizontal_spacing * (cols - 1 )) / cols
910
+ # Set height of each subplot cell (excluding padding)
913
911
height = (1. - vertical_spacing * (rows - 1 )) / rows
914
912
913
+ try :
914
+ column_width = kwargs ['column_width' ]
915
+ if not isinstance (column_width , list ) or len (column_width ) != cols :
916
+ raise Exception (
917
+ "Keyword argument 'column_width' must be a list "
918
+ "containing the same number of floats as the number of cols."
919
+ )
920
+ except KeyError :
921
+ column_width = None
922
+
923
+ if column_width :
924
+ cum_sum = float (sum (column_width ))
925
+ widths = []
926
+ for w in column_width :
927
+ widths .append (
928
+ (1. - horizontal_spacing * (cols - 1 )) * (w / cum_sum )
929
+ )
930
+ else :
931
+ widths = [(1. - horizontal_spacing * (cols - 1 )) / cols ] * cols
932
+
915
933
# Built row/col sequence using 'row_dir' and 'col_dir'
916
934
COL_DIR = START_CELL ['col_dir' ]
917
935
ROW_DIR = START_CELL ['row_dir' ]
918
936
col_seq = range (cols )[::COL_DIR ]
919
937
row_seq = range (rows )[::ROW_DIR ]
920
938
921
939
# [grid] Build subplot grid (coord tuple of cell)
922
- grid = [[((width + horizontal_spacing ) * c ,
923
- (height + vertical_spacing ) * r )
924
- for c in col_seq ]
925
- for r in row_seq ]
926
-
927
- import pprint
928
- pprint .pprint (grid )
940
+ grid = [
941
+ [
942
+ (
943
+ (sum (widths [:c ]) + c * horizontal_spacing ),
944
+ (height + vertical_spacing ) * r
945
+ ) for c in col_seq
946
+ ] for r in row_seq
947
+ ]
929
948
930
949
# [grid_ref] Initialize the grid and insets' axis-reference lists
931
950
grid_ref = [[None for c in range (cols )] for r in range (rows )]
@@ -1042,15 +1061,9 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
1042
1061
raise Exception ("Some 'rowspan' value is too large for "
1043
1062
"this subplot grid." )
1044
1063
1045
- print grid [r ][c ]
1046
- print grid [r ][c_spanned ]
1047
- print "width is {}" .format (width )
1048
- print "height is {}" .format (height )
1049
- print '\n \n '
1050
-
1051
1064
# Get x ___domain using grid and colspan
1052
1065
x_s = grid [r ][c ][0 ] + spec ['l' ]
1053
- x_e = grid [r ][c_spanned ][0 ] + width - spec ['r' ]
1066
+ x_e = grid [r ][c_spanned ][0 ] + widths [ c ] - spec ['r' ]
1054
1067
x_domain = [x_s , x_e ]
1055
1068
1056
1069
# Get y ___domain (dep. on row_dir) using grid & r_spanned
@@ -1118,11 +1131,11 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
1118
1131
"Note: the starting cell is (1, 1)" )
1119
1132
1120
1133
# Get inset x ___domain using grid
1121
- x_s = grid [r ][c ][0 ] + inset ['l' ] * width
1134
+ x_s = grid [r ][c ][0 ] + inset ['l' ] * widths [ c ]
1122
1135
if inset ['w' ] == 'to_end' :
1123
- x_e = grid [r ][c ][0 ] + width
1136
+ x_e = grid [r ][c ][0 ] + widths [ c ]
1124
1137
else :
1125
- x_e = x_s + inset ['w' ] * width
1138
+ x_e = x_s + inset ['w' ] * widths [ c ]
1126
1139
x_domain = [x_s , x_e ]
1127
1140
1128
1141
# Get inset y ___domain using grid
0 commit comments