@@ -807,8 +807,7 @@ def make_subplots(rows=1, cols=1,
807807
808808 # Throw exception if non-valid kwarg is sent
809809 VALID_KWARGS = ['horizontal_spacing' , 'vertical_spacing' ,
810- 'specs' , 'insets' , 'subplot_titles' , 'column_width' ,
811- 'row_width' ]
810+ 'specs' , 'insets' , 'subplot_titles' , 'column_width' ]
812811 for key in kwargs .keys ():
813812 if key not in VALID_KWARGS :
814813 raise Exception ("Invalid keyword argument: '{0}'" .format (key ))
@@ -908,24 +907,44 @@ def _checks(item, defaults):
908907 )
909908 _check_keys_and_fill ('insets' , insets , INSET_defaults )
910909
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)
913911 height = (1. - vertical_spacing * (rows - 1 )) / rows
914912
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+
915933 # Built row/col sequence using 'row_dir' and 'col_dir'
916934 COL_DIR = START_CELL ['col_dir' ]
917935 ROW_DIR = START_CELL ['row_dir' ]
918936 col_seq = range (cols )[::COL_DIR ]
919937 row_seq = range (rows )[::ROW_DIR ]
920938
921939 # [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+ ]
929948
930949 # [grid_ref] Initialize the grid and insets' axis-reference lists
931950 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):
10421061 raise Exception ("Some 'rowspan' value is too large for "
10431062 "this subplot grid." )
10441063
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-
10511064 # Get x domain using grid and colspan
10521065 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' ]
10541067 x_domain = [x_s , x_e ]
10551068
10561069 # 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):
11181131 "Note: the starting cell is (1, 1)" )
11191132
11201133 # 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 ]
11221135 if inset ['w' ] == 'to_end' :
1123- x_e = grid [r ][c ][0 ] + width
1136+ x_e = grid [r ][c ][0 ] + widths [ c ]
11241137 else :
1125- x_e = x_s + inset ['w' ] * width
1138+ x_e = x_s + inset ['w' ] * widths [ c ]
11261139 x_domain = [x_s , x_e ]
11271140
11281141 # Get inset y domain using grid
0 commit comments