@@ -772,6 +772,32 @@ def make_subplots(rows=1, cols=1,
772772 in fraction of cell height
773773 * h (float or 'to_end', default='to_end') inset height
774774 in fraction of cell height ('to_end': to cell top edge)
775+
776+ column_width (kwarg, list of numbers)
777+ Column_width specifications
778+
779+ - Functions similarly to `column_width` of `plotly.graph_objs.Table`.
780+ Specify a list that contains numbers where the amount of numbers in
781+ the list is equal to `cols`.
782+
783+ - The numbers in the list indicate the proportions that each column
784+ domains take across the full horizontal domain excluding padding.
785+
786+ - For example, if columns_width=[3, 1], horizontal_spacing=0, and
787+ cols=2, the domains for each column would be [0. 0.75] and [0.75, 1]
788+
789+ row_width (kwargs, list of numbers)
790+ Row_width specifications
791+
792+ - Functions similarly to `column_width`. Specify a list that contains
793+ numbers where the amount of numbers in the list is equal to `rows`.
794+
795+ - The numbers in the list indicate the proportions that each row
796+ domains take along the full vertical domain excluding padding.
797+
798+ - For example, if row_width=[3, 1], vertical_spacing=0, and
799+ cols=2, the domains for each row from top to botton would be
800+ [0. 0.75] and [0.75, 1]
775801 """
776802 # TODO: protected until #282
777803 from plotly .graph_objs import graph_objs
@@ -807,7 +833,8 @@ def make_subplots(rows=1, cols=1,
807833
808834 # Throw exception if non-valid kwarg is sent
809835 VALID_KWARGS = ['horizontal_spacing' , 'vertical_spacing' ,
810- 'specs' , 'insets' , 'subplot_titles' ]
836+ 'specs' , 'insets' , 'subplot_titles' , 'column_width' ,
837+ 'row_width' ]
811838 for key in kwargs .keys ():
812839 if key not in VALID_KWARGS :
813840 raise Exception ("Invalid keyword argument: '{0}'" .format (key ))
@@ -907,9 +934,47 @@ def _checks(item, defaults):
907934 )
908935 _check_keys_and_fill ('insets' , insets , INSET_defaults )
909936
910- # Set width & height of each subplot cell (excluding padding)
911- width = (1. - horizontal_spacing * (cols - 1 )) / cols
912- height = (1. - vertical_spacing * (rows - 1 )) / rows
937+ # set heights (with 'column_width')
938+ try :
939+ column_width = kwargs ['column_width' ]
940+ if not isinstance (column_width , list ) or len (column_width ) != cols :
941+ raise Exception (
942+ "Keyword argument 'column_width' must be a list with {} "
943+ "numbers in it, the number of subplot cols." .format (cols )
944+ )
945+ except KeyError :
946+ column_width = None
947+
948+ if column_width :
949+ cum_sum = float (sum (column_width ))
950+ widths = []
951+ for w in column_width :
952+ widths .append (
953+ (1. - horizontal_spacing * (cols - 1 )) * (w / cum_sum )
954+ )
955+ else :
956+ widths = [(1. - horizontal_spacing * (cols - 1 )) / cols ] * cols
957+
958+ # set widths (with 'row_width')
959+ try :
960+ row_width = kwargs ['row_width' ]
961+ if not isinstance (row_width , list ) or len (row_width ) != rows :
962+ raise Exception (
963+ "Keyword argument 'row_width' must be a list with {} "
964+ "numbers in it, the number of subplot rows." .format (rows )
965+ )
966+ except KeyError :
967+ row_width = None
968+
969+ if row_width :
970+ cum_sum = float (sum (row_width ))
971+ heights = []
972+ for h in row_width :
973+ heights .append (
974+ (1. - vertical_spacing * (rows - 1 )) * (h / cum_sum )
975+ )
976+ else :
977+ heights = [(1. - vertical_spacing * (rows - 1 )) / rows ] * rows
913978
914979 # Built row/col sequence using 'row_dir' and 'col_dir'
915980 COL_DIR = START_CELL ['col_dir' ]
@@ -918,10 +983,14 @@ def _checks(item, defaults):
918983 row_seq = range (rows )[::ROW_DIR ]
919984
920985 # [grid] Build subplot grid (coord tuple of cell)
921- grid = [[((width + horizontal_spacing ) * c ,
922- (height + vertical_spacing ) * r )
923- for c in col_seq ]
924- for r in row_seq ]
986+ grid = [
987+ [
988+ (
989+ (sum (widths [:c ]) + c * horizontal_spacing ),
990+ (sum (heights [:r ]) + r * vertical_spacing )
991+ ) for c in col_seq
992+ ] for r in row_seq
993+ ]
925994
926995 # [grid_ref] Initialize the grid and insets' axis-reference lists
927996 grid_ref = [[None for c in range (cols )] for r in range (rows )]
@@ -1040,16 +1109,16 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
10401109
10411110 # Get x domain using grid and colspan
10421111 x_s = grid [r ][c ][0 ] + spec ['l' ]
1043- x_e = grid [r ][c_spanned ][0 ] + width - spec ['r' ]
1112+ x_e = grid [r ][c_spanned ][0 ] + widths [ c ] - spec ['r' ]
10441113 x_domain = [x_s , x_e ]
10451114
10461115 # Get y domain (dep. on row_dir) using grid & r_spanned
10471116 if ROW_DIR > 0 :
10481117 y_s = grid [r ][c ][1 ] + spec ['b' ]
1049- y_e = grid [r_spanned ][c ][1 ] + height - spec ['t' ]
1118+ y_e = grid [r_spanned ][c ][1 ] + heights [ - 1 - r ] - spec ['t' ]
10501119 else :
10511120 y_s = grid [r_spanned ][c ][1 ] + spec ['b' ]
1052- y_e = grid [r ][c ][1 ] + height - spec ['t' ]
1121+ y_e = grid [r ][c ][1 ] + heights [ - 1 - r ] - spec ['t' ]
10531122 y_domain = [y_s , y_e ]
10541123
10551124 if spec ['is_3d' ]:
@@ -1108,19 +1177,19 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
11081177 "Note: the starting cell is (1, 1)" )
11091178
11101179 # Get inset x domain using grid
1111- x_s = grid [r ][c ][0 ] + inset ['l' ] * width
1180+ x_s = grid [r ][c ][0 ] + inset ['l' ] * widths [ c ]
11121181 if inset ['w' ] == 'to_end' :
1113- x_e = grid [r ][c ][0 ] + width
1182+ x_e = grid [r ][c ][0 ] + widths [ c ]
11141183 else :
1115- x_e = x_s + inset ['w' ] * width
1184+ x_e = x_s + inset ['w' ] * widths [ c ]
11161185 x_domain = [x_s , x_e ]
11171186
11181187 # Get inset y domain using grid
1119- y_s = grid [r ][c ][1 ] + inset ['b' ] * height
1188+ y_s = grid [r ][c ][1 ] + inset ['b' ] * heights [ - 1 - r ]
11201189 if inset ['h' ] == 'to_end' :
1121- y_e = grid [r ][c ][1 ] + height
1190+ y_e = grid [r ][c ][1 ] + heights [ - 1 - r ]
11221191 else :
1123- y_e = y_s + inset ['h' ] * height
1192+ y_e = y_s + inset ['h' ] * heights [ - 1 - r ]
11241193 y_domain = [y_s , y_e ]
11251194
11261195 if inset ['is_3d' ]:
0 commit comments